Tips for Using Windsurf Effectively

Recently, I have been using Windsurf for about half a month, and my feeling is that this tool is very powerful, comparable to cursor. I previously tried the free cursor, but the number of completions ran out quickly. The experience was indeed great, but the $20 price tag requires careful consideration. Later, I started using Windsurf, which is only half the price of cursor (not sure when it will drop to $15), but it still maintains an excellent experience. Therefore, today I will share some insights about my usage of Windsurf.

Utilize Rules Configuration Wisely

The rules feature in Windsurf was launched about a week ago. The most significant inconvenience before this was that if the conversation did not specify otherwise, the replies would be in English. Therefore, if you want it to respond in Chinese, you can directly configure it in the rules, which can be understood as a <span>System Prompt</span>. A well-designed rules configuration can greatly enhance the model’s output quality. This feature has long been available in cursor, and there is a repository online that collects many excellent configurations: https://github.com/PatrickJS/awesome-cursorrules. You can check it out to see if there’s something suitable for you.

My suggestion for rules configuration is to first clarify the role background. For example, I am a Java developer, so I would tell it:

Role Background: 
    - You are an experienced senior Java architect. 
    - Always adhere to SOLID principles, DRY principles, KISS principles, and YAGNI principles. 
    - Follow OWASP best practices. 
    - Good at breaking tasks down into the smallest units and solving problems step by step. 
    - Answer my questions in Chinese.

This segment is also recommended from the repository, mainly to enable the model to provide best practice code and avoid low-quality code affecting the overall code quality.

Moreover, rules can be set globally or for a specific workspace. For workspace rules, you can provide details about the technology stack and directory structure. For example:

Technology Stack: 
    - Framework: JavaSpringBoot2, Maven, Java8 
    - Dependencies: MybatisPlus, Lombok, PostgreSQL driver, Redis, ShardingJDBC 

Project Background: xx engine system, mainly used to solve... 

Project Structure: 
- common: Common dependency package, core and starter will depend on this module 
- constants: Constant classes 
- mq: Message transfer defined objects 
- core: Core business development module 
- entity: Database entities 
- mapper: Database mappers 
- service: Service classes and interfaces 
- db: Simple service generated based on MybatisPlus framework and its implementation 
- biz: Specific implementation services 
- controller: RestController layer 
- mq: Message processing handlers 
- filter: Some filters 
- config: System configuration 
- starter: Spring Boot starter for other business systems 
- config starter: Configuration of the starter 
- client: Some encapsulated clients for requests to the current project

The benefit of clarifying this background knowledge is that it allows the model to design code more specifically for this project, especially when modifications often cross files, which can help avoid locating the wrong files or using solutions that are not suitable for the current technology stack.

Good Code Style

During the development of new projects, try to make a preliminary design of the code architecture. You can use some design patterns or architectural design ideas to build the overall development style. For example, if you use the template pattern, what you ultimately want to achieve is based on the implementation of several methods provided by the template, effectively splitting the business logically. When you implement one piece of business code, you can use the already implemented code as reference when implementing other subclasses that inherit from the template class. The specific operation is to select the reference code you want to provide to the model, and then click chat; the reference will appear in the right input box, similar to a few-shot approach, making its responses more accurate. The actual prompt is roughly as follows:

Please refer to (selected code reference) to complete (the code to be modified reference): 
(You can also add some requirement content)

If you are unsure how to design a better code architecture, you can also directly ask it for suggestions through conversation. This is not only advice for using Windsurf but also a new development mindset for programmers in the AI-assisted era. AI is like a rubber duck that thinks along with you.

The code style here includes but is not limited to design patterns, good naming conventions, appropriate module splitting, accurate code comments, etc., which are all very helpful for the model to understand the current repository’s code.

Appropriate Use of Prompting Techniques

In Windsurf, the requirements for prompts are much lower compared to directly using the model for conversation, but effective prompts can still yield better feedback. For example, the few-shot approach mentioned above is applicable in real business development where there are many logically similar codes. Therefore, use it whenever possible to avoid the model deviating into writing code in other styles.

Additionally, a crucial technique is the chain of thought. Even though we can see that Windsurf is also thinking step by step during the conversation, if you already have a clear idea, don’t hesitate to write a few more lines to convey your thoughts to it. This is much more efficient than correcting it after it has gone off track.

Finally, I want to say that as programmers, we must keep up with the current AI era. We should neither believe that AI can replace programmers nor reject the use of AI tools. Therefore, we should maintain an objective attitude toward AI. After using it for a while, you will almost sense the model’s capability boundaries, and naturally, you’ll be able to leverage it to enhance your work efficiency.

Hi, I am Yezi, a Java developer with 7 years of experience. I have worked in various companies, including startups and publicly listed companies. I am proficient in various types of CRUD, but currently, I am focusing on backend development and transitioning to microservices. I love AI technologies and I am motivated to learn continuously. I hope to share knowledge and progress with everyone in the technical community. If this article is useful, please like and follow. I hope we can walk further together on the technical path!

Leave a Comment