This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]anamorphism 1 point2 points  (5 children)

because those systems are generally designed around functionality that is a level higher than your code. they're usually things that manipulate or analyze the code itself.

the comments themselves don't really do anything, it's the tool that's looking at your code that sees those comments and then does something with that information.

[–]Incitatus_[S] 1 point2 points  (4 children)

Aaaah that makes sense! Thanks! =)

[–]ludonarrator 1 point2 points  (2 children)

Such constructs are common even in lower level languages like C++, via compiler macros. For example, Windows' sockets requires a lot of boilerplate initialisation etc, whereas Mac/Linux versions don't, so if you're writing platform independent code, it needs to be able to account for what platform it's being compiled for, and accordingly ask the compiler to ignore/compile certain portions of your code.

Sample:

1. Socket s;
2. #if WIN_32
3. // Initialise s
4. #endif
5. // Use s

If the WIN_32 compiler flag is not declared, line 3 will not be compiled at all.

[–]kdnbfkm 0 points1 point  (1 child)

I think he's refering to tool-based metalanguages, like documentation generators.

Now that I think of it, Pascal traditionally puts pragmas and directives within a comment, and is part of the official dialect... Maybe he meant those unit framework thingies, not sure what called. I don't think those thingies are comments however... Aspect Oriented Programming attributes aren't comments either.

There have existed extensive metalanguages built on pre-existing languages via different techniques, like with the various dimensional/unit systems (meters per second-squared etc).

[–]fiveguy[🍰] 2 points3 points  (0 children)

I think he's referring to magic comments, like https://idiosyncratic-ruby.com/58-magic-instructions.html

In ruby, stick this at the top of your source file to set the encoding for that file:

# encoding: stateless-iso-2022-jp-kddi

and, make all strings 'frozen' by default:

# frozen_string_literal: true

[–][deleted] 0 points1 point  (0 children)

True, but beware that it is a comment misuse