• Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
  • Tips
  • QA’s
  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
  • Tips
  • QA’s
  • #News
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk
  • #Interview
  • #Tips

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
  • Tips
  • QA’s
Tips&Tricks

Comment Styles in Different Programming Languages.

Comment Styles, 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.

The flexibility provided by comments allows for a wide degree of variability, but formal conventions for their use are commonly part of programming style guides.

How best to make use of comments is subject to dispute; different commentators have offered varied and sometimes opposing viewpoints. There are many different ways of writing comments and many commentators offer conflicting advice.

Ada

The Ada programming language uses ‘–‘ to indicate a comment up to the end of the line.

  -- your comment
  -- your comment

AppleScript

This section of AppleScript code shows the two styles of comments used in that language.

(*
your comment
*)

-- Show the greeting

BASIC

In this classic early BASIC code fragment the REM (“Remark”) keyword is used to add comments.

Microsoft BASICs, including Quick Basic, Q Basic, Visual Basic, Visual Basic .NET, and VB Script; and in descendants such as FreeBASIC and Gambas any text on a line after an ‘ (apostrophe) character is also treated as a comment.

10 REM your comment
15 REM your comment

' your comment
' your comment
rem your comment.

C

This C code fragment demonstrates the use of a prologue comment or “block comment” to describe the purpose of a conditional statement.

 /*
  * your comment
  * your comment
  * your comment
  * your comment
  */

ColdFusion

ColdFusion uses comments similar to HTML comments, but instead of two dashes, it uses three. These comments are caught by the ColdFusion engine and not printed to the browser.

<!--- your comment --->

Fortran IV

This Fortran IV code fragment demonstrates how comments are used in that language, which is very column-oriented. A letter “C” in column 1 causes the entire line to be treated as a comment.

C
C your comment
C

Haskell

Line comments in Haskell start with ‘–‘ (two hyphens) until the end of the line, and multiple line comments start with ‘{-‘ and end with ‘-}’.

{- your comment
your comment -}

-- your comment

Java

This Java code fragment shows a block comment used to describe the method. The formatting is consistent with Sun Microsystems Javadoc standards. The comment is designed to be read by the Javadoc processor.

/**
 * your comment
 */

// your comment

JavaScript

JavaScript uses // to precede comments and /* */ for multi-line comments.

// A single line JavaScript comment

/*
multi-line
JavaScript comment
*/

Lua

The Lua programming language uses double-hyphens, –, for single line comments in a similar way to Ada, Eiffel, Haskell, SQL and VHDL languages. Lua also has block comments, which start with –[[ your comment goes here ]]

--[[
Code block for comment or un-used code
--]]

-- no action (commented out)

MATLAB

In MATLAB’s programming language, the ‘%’ character indicates a single-line comment. Multi-line comments are also available via %{ and %} brackets and can be nested

% Single Line Comments

%{
    Multiline Comments
  
 %}

Nim

Nim uses the ‘#’ character for inline comments. Multi-line block comments are opened with ‘#[‘ and closed with ‘]#’. Multi-line block comments can be nested.

## Documentation of the module 
# This is a comment, but it is not a documentation comment.

#[' your Comments ']#

Objective-C

Objective-C uses // to precede comments

// A single line Objective-C comment

OCaml

OCaml uses nestable comments, which is useful when commenting a code block.

(* comment level 1(*comment level 2*)*)

Pascal

In pascal comments are opened with ‘(‘ and completed with ‘)’.

(* comment here *)

Perl

Line comments in Perl, and many other scripting languages, begin with a hash (#) symbol.

# A simple Comment

R

R only supports inline comments started by the hash (#) character.

# your Comments

PHP

Comments in PHP can be either in C++ style (both inline and block), or use hashes. PHPDoc is a style adapted from Javadoc and is a common standard for documenting PHP code.

# Single line comment

Python

Inline comments in Python use the hash (#) character

# your Comments

Ruby

Single line comments: (line starts with hash “#”)

# this is a comment

Multi-line commenting: (comments goes between keywords "begin" and "end")

=begin

your Comments

your Comments

=end

SQL

Standard comments in SQL are in single-line-only form.

-- your Comments
-- your Comments

Swift

Single-line comments begin with two forward-slashes (//):

// This is a comment.

/* your Comments
 your Comments */

XML (or HTML)

Comments in XML (or HTML) with , single and multiline comments

<!-- your Comments -->

Happy Commenting 🙂

Liked it? Take a second to support Ranjan on Patreon!
Become a patron at Patreon!
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 2129 Views
Tags | Tips & Tricks
AUTHOR
Ranjan

Namaste, My name is Ranjan, I am a graduate from NIT Rourkela. This website is basically about of what i learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures, its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

You Might Also Like

mycodetips-newlogo2

Use Your MAC Without a Mouse-Part2

October 16, 2013
Productive Web Developer

6 Ways to Be a More Productive Web Developer

September 17, 2021
mycodetips-newlogo2

Work on MAC-OSX without using mouse or Touchpad

October 15, 2013
Next Post
Previous Post

Support us

Subscribe for updates

Join 8,220 other subscribers

Latest Posts

  • YT-Featured-Templates--lld
    What Business Problems Solves in Low Level Design (LLD)
  • SRP-SingleResopnsibility
    SRP : Single Responsibility Principle in Swift and Objective-C
  • Designing Mobile APPS
    Limitation and restriction of designing mobile apps
  • YT-Featured-solidprinciples
    SOLID Principles of Software Design
  • IOS 16 Features
    Latest features in IOS 16
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

do2day

Do2Day

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #myQuestions

.Net Android Blogging Cloud Concept Database DSA ERROR ExcelTips Flutter Interview IOS IOSQuestions JAVA Javascript MAC-OS No-Mouse Objective-c Programming Quick Tips SEO Software Design & Architecture Swift SwiftUI Tips&Tricks Tools Troubleshoot Videos Web Wordpress Xamarin XCode

  • What Business Problems Solves in Low Level Design (LLD)
  • SRP : Single Responsibility Principle in Swift and Objective-C
  • Limitation and restriction of designing mobile apps
  • SOLID Principles of Software Design
  • Latest features in IOS 16
MyCodeTips

©mycodetips.com