Color matters
As software developers, we read, and write codes every work day. Code with color highlighting is one of critical features provided by IDE.
Recently, there is a new technique
semantic highlighting
provided by IDEs (vscode, pycharm, etc), which is an advance version of syntax highlighting
. I strongly recommend readers to enable it NOW. (I got this technique from this blog post)Syntax highlighting
Firstly, let me try to convince you why color matters on dealing with codes by showing the syntax highlighting feature on / off.
Below is a snippet captured from Django RegexValidator.
With syntax highlighting | No Color |
---|---|
As the feature name
syntax highlighting
suggested, we can easily tell variables, keywords, and class names from sea of codes.
IMO, I will be dead if there is no syntax highlighting when reading codes.
Semantic highlighting
While syntax highlighting colorizes codes based on coding syntax,
Semantic highlighting
colorizes codes based on the semantic. Take a look the comparison below if you are not sure the differences between them.With syntax highlighting | With semantic highlighting |
---|---|
In syntax highlighting, variables are all in same color while they have an unique color in semantic highlighting.
Variables are same type of syntax. Therefore, they share same color in syntax highlighting. But, in semantic point of view, they are differences. Therefore, each of them has unique color.
IMO, semantic highlighting is far more useful than the syntax highlighting. By reading the colors, you can tell the scope of a variable.
This is VERY critical for writing / debugging codes. Given a sea of variables inside a function, if they are in same color, you need to understand each of them to find out which one is wrong. With semantic highlighting, your work maybe easier by simply reading colors inside that function.
Honestly, the visual impact between two highlighting is smaller than the one between color on / off. But, I am still strongly recommend you to enable semantic highlighting NOW.
By the help of
semantic highlighting
, I am more confident to write correct codes at the first time.Let’s enable semantic highlighting. But how?
Pycharm
Since I am a fan of pycharm, below is the manual for enabling semantic highlighting
Other IDEs
Modern IDEs nowaday have a search function. You can find the switch by just typing semantic highlighting inside that search function.
Customize the color scheme
To save our times on configuring coding colors, there are feature named as color scheme, which pre-configure colors for you. Instead of setup from scratch, I recommend readers to start from picking color themes.
There are lots of builtin color themes for you to select in modern IDEs. If none of them fulfill what you need, you can download color themes, as a plugin, from other developers.
Personally, I am using a color theme from GAP
Of cause, you can still fine tune the colors in each color scheme in your IDE settings.
Tips on testing colors in PYCHARM
- Switching theme quickly
By hotkey ctrl+`, you can invoke a color menu for you to switch color theme.
References
- https://www.jetbrains.com/help/pycharm/configuring-colors-and-fonts.html
- https://blog.jetbrains.com/pycharm/2017/01/make-sense-of-your-variables-at-a-glance-with-semantic-highlighting/
- https://gaplo.tech/productivity-and-semantic-highlighting/?fbclid=IwAR0o0qXKBKpBwPPwvKIIYa10aDLk6VYRwKXC5EKhJ9EoYItMLMPHzM4necA
沒有留言:
張貼留言