Search code examples
programming-languagescomments

What is the usage of Nested comments in some programming languages?


Why nested comments use by some programming languages such as MATLAB ,I just want to know usage of this kind comments in a program and what are the advantages we can gain by using this nested comments ?


Solution

  • Usually, coding standards for a particular project or program have rules about which comment style to use when; a common convention is to use block comments (/* */) for method and class documentation, and inline comments (//) for remarks inside method bodies and such, e.g.:

    /**
     * Helper class to store Foo objects inside a bar.
     */
    public class Foobar {
        /**
         * Stores a Foo in this Foobar's bar, unless the bar already contains
         * an equivalent Foo.
         * Returns the number of Foos added (always 0 or 1).
         */
        public int storeFoo(Foo foo) {
            // Don't add a foo we already have!
            if (this.bar.contains(foo)) {
                return 0;
            }
            // OK, we don't have this foo yet, so we'll add it.
            this.bar.append(foo);
            return 1;
        }
    }
    

    If someone wants to temporarily disable entire methods or classes in the above program.It's very helpful, if that language allows nested comments.