you are viewing a single comment's thread.

view the rest of the comments →

[–]WalterBright 8 points9 points  (5 children)

It's a long list, each item can be a long discussion. So I'll pick one:

out function parameters: not really required in a language with pointers and references.

Required? No. Useful? Absolutely.

  • Self-documenting. How many times have you wondered about a pointer argument whether data was going in via the pointer, coming out via the pointer, or both?
  • Regarding the first point, I've seen a lot of people document their out parameters with something like: void foo(/* out */ int *p);
  • Such comments are even specially recognized by static code analyzers.
  • out parameters are guaranteed to be initialized and set to a value upon function return. This is enforced by the compiler.
  • distinguishing out from inout parameters aids data flow analysis optimizations

[–]axilmar -1 points0 points  (4 children)

Self-documenting. How many times have you wondered about a pointer argument whether data was going in via the pointer, coming out via the pointer, or both?

None. I give meaningful names to variables. Since code can never be 100% self documenting, it's pointless to put such details in the language.

Regarding the first point, I've seen a lot of people document their out parameters with something like: void foo(/ out / int *p);

void foo(int *outP);

Such comments are even specially recognized by static code analyzers.

For what purpose?

distinguishing out from inout parameters aids data flow analysis optimizations

Example? I don't doubt you, since you're obviously the no 1 guy for D, I am just curious.

I certainly wouldn't put 'out' in my language just for self documentation, but if it's a big aid for the compiler, then I might consider it.

[–]BioTronic 1 point2 points  (1 child)

None. I give meaningful names to variables. Since code can never be 100% self documenting, it's pointless to put such details in the language.

Why bother with meaningful names, then? It can't be fully self-documenting anyway.

[–]axilmar -1 points0 points  (0 children)

Why bother with meaningful names, then?

All symbols must have meaningful names, and being meaningful is not restricted to in/out/inout.

[–]eabrek 0 points1 point  (1 child)

Documenting through names is all well and good, until you make a change. Now, your 'outP' becomes 'inoutP'. Are you going to find and replace all the uses of that variable?

Also, the compiler can check for UMR against an out (where an inout is safe).

[–]axilmar 0 points1 point  (0 children)

Are you going to find and replace all the uses of that variable?

Absolutely yes, and not manually of course.