commented blocks of code

I was reading an article about maintainable JavaScript, and thought I’d comment on it about a method I use to keep my own JavaScript clean.

Although this is about JavaScript, the exact same trick works in PHP as well.

A method I use for commenting also helps me to create navigable code. I use vim for coding, which allows me to “fold” at the ‘{‘ mark, making blocks and functions into hierarchical trees.

A useful thing about this, is that you can then place your comment after the ‘{‘.

screenshot.png

For example, check out this code.

Scattered throughout the code, you can find blocks starting with “{ //“.

A handy thing about the {..} syntax, is that it doesn’t actually need to follow an if/function()/for() qualifier! This means that you can logically separate your code into blocks of contextually similar code.

kdevelop and other IDEs also allow you to fold at the'{‘ mark.

2 Replies to “commented blocks of code”

Comments are closed.