Author Topic: unifying '->' and '.' member accessors  (Read 16398 times)

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
unifying '->' and '.' member accessors
« on: March 07, 2013, 07:58:40 AM »
Hi,

I'm wondering whether to unify the accessors -> (for pointer types) and . (dot) for non-pointer structs/unions.
So both pointer and non-pointer types would simply use the dot. no more a->b.c, just a.b.c
The compiler can easily detect this, so implementation wont be a problem i think.

The advantage of this would be that it's easier for the programmer and less work when changing types from pointer
to non-pointer or reverse.
The dis-advantage would be that it doesn't show the member type at the calling site. I personally don't think this
is bad.

Any feedback?


norm

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: unifying '->' and '.' member accessors
« Reply #1 on: March 15, 2013, 05:33:30 AM »
I definitely would prefer this.

Looking around at other languages, I see that Modula-3 and Oberon both allow struct.field as shorthand for struct^.field (where ^ is the dereference operator in those languages), and Ada allows struct.field as shorthand for struct.all.field (where .all is the dereference operator in Ada, if I'm reading correctly).




liviugb

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: unifying '->' and '.' member accessors
« Reply #2 on: March 27, 2013, 09:42:34 PM »
That would be an improvement in my opinion too. Coming from languages like C#, Java or even Go it's very easy to use the dot instead of ->. Speaking of Go, I think it is a very nice language to take inspiration from. Go has a very simple & consistent syntax and a nice module system which made it very successful. The only problem with Go is that it is not 100% inter operable with C code (you can call C functions from Go but not the other way) and has a garbage collector. C2 can take this niche: best principles from Go + 100% interop with C + no garbage collector.

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: unifying '->' and '.' member accessors
« Reply #3 on: March 29, 2013, 10:24:45 AM »
Seems everyone is in favour, I'll put this on the list of things to be done. Hopefully it'll be in the next few weeks..