DEV Community

Cover image for What are the best comments?
Kavindu Santhusa
Kavindu Santhusa

Posted on • Originally published at unv.vercel.app

What are the best comments?

Many programming languages are using comments. But they are using different syntax for it. I am going to choose the best syntax.

In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters. The syntax of comments in various programming languages varies considerably.

I am creating a programming language named Unv. So I wanted to implement comments.

Vist the Unv website for more info.

There are 2 types of comments.

  • inline comments
  • block comments

Inline comments

Inline comments are generally those that use a newline character to indicate the end of a comment, and an arbitrary delimiter or sequence of tokens to indicate the beginning of a comment.

C like languages are using double slashes to define an inline comment.

// This is an inline comment
Enter fullscreen mode Exit fullscreen mode

Python is using a # sign to define it.

# This is an inline comment
Enter fullscreen mode Exit fullscreen mode

C-like syntax is more popular (I think), But python comments are more clear for me. They are differ from other symbol used in code and easy to understand(with or without syntax highlighting).

So Unv comments are similar to Python.
You can try it on the playground.

Block comments

Block comments are generally those that use a delimiter to indicate the beginning of a comment, and another delimiter to indicate the end of a comment. In this context, whitespace and newline characters are not counted as delimiters.

C-like languages are using /* mark to start a block comment and a */ mark to end it.

/*
 This is a block comment
*/
Enter fullscreen mode Exit fullscreen mode

In python normally you should use many inline comments to define a block comment.

# This is a
# block
# comment
Enter fullscreen mode Exit fullscreen mode

It's valid for Unv too. You can try it on the playground.
But you can use a multiline string to define a block comment.

"""
This is a
block
comment
"""
Enter fullscreen mode Exit fullscreen mode

In Unv programming language, strings are always multiline. So similar code is always valid for Unv.

"
This is a
block
comment
"
Enter fullscreen mode Exit fullscreen mode

You can try it on the playground.

###
This is a
block
comment
###
Enter fullscreen mode Exit fullscreen mode

Oh it was already used by CoffeeScript. for Unv You can try it on the playground

They are my favourites. If you have ideas please let me know. You can contact me via ksengine.github@gmail.com .

Top comments (0)