c2compiler icon indicating copy to clipboard operation
c2compiler copied to clipboard

Naming conventions for "private" struct members.

Open lerno opened this issue 7 years ago • 2 comments

I was looking at this: https://github.com/c2hub/c2vector/blob/master/c2vector/c2vector.c2

And realized that maybe C2 needs a convention (or a way) to name / signal "internal" (I wouldn't use 'private') fields.

There are a few options:

  1. Name convention: "_foo" – Dart does this, and they actually skip "private/public" by saying anything with "_" is private.
  2. Keyword: "private foo" / "internal foo" / "local foo" in the struct declaration together with have to use some special way to get hold of it. In the case of c2vector2: c = v.capacity and maybe a = v.$total or c = (private v).total or c = private v.total (not beautiful solutions, just describing the options we have)
  3. Sigil: e.g. "$foo" like in type Foo struct { int $foo; }

lerno avatar Nov 25 '18 18:11 lerno

This is related to the discussions on whether to allow struct functions to use (struct) variables without the self. prefix. Just like C++ etc. I think this will make a lot of code more readable. C2 does (will) not have the public/private stuff, but it might be good to signal a member access. This does make the case var.member and (in structfunc) _member different... Hmm

bvdberg avatar Nov 27 '18 10:11 bvdberg

If it was a lang from scratch I would have suggested a sigil if you wanted to access a struct member in a struct function, but that is too much of a change I think.

In JaI, ”using X” would give direct access to members in the function.

I’m two minds about this. Because having to deal with access directly emphasises the fact that one must deal with the null-pointer scenario.

lerno avatar Nov 27 '18 11:11 lerno