Help: how to add `this` feature to my go source?

95 views
Skip to first unread message

Wang Yarco

unread,
Sep 30, 2016, 11:25:25 PM9/30/16
to golang-nuts
Though there's no strict rule to name the instance when defining a method of the struct:
type user struct {
  name
string
  age
int
}

func
(u *user) say() {
 
// ...
}

Here we use `u`, but i still miss `this` feature, it does't mean i should use `this`, below is my idea:
func (*user) say(){ // if want anonymous instance name??
  fmt
.Println(ts.name, this.age); // the default `this` name can be both `ts` and `this` or something i like to name
}

func
(u *user) whatever() { // then i also could define one
  fmt
.Println(u.name, u.age); // u overwrite using `ts` and `this`
}

// both code should work

I'm not going to say i wanna change the go lang syntax, but i do prefer to add this to my golang version......so How? ( Or if it is complex, i leave it to the future version of me)

Justin Israel

unread,
Sep 30, 2016, 11:44:58 PM9/30/16
to Wang Yarco, golang-nuts
If you were able to apply this functionality to your own version of your Go compiler, how would you end up dealing with your code being unable to compile for anyone else? Would you just not distribute this code? 



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wang Yarco

unread,
Oct 1, 2016, 1:05:57 AM10/1/16
to golang-nuts, yarco...@gmail.com
> how would you end up dealing with your code being unable to compile for anyone else? 
I think if i do have my own golang version app code, those are all used for my own purpose (i don't think i'm a strong coding guy -- at the system level,  where who can make the code world wide used)
It must be something like customizing bash, adding some alias commands -- at application level...
And if it is truly welcomed by everyone (like if `ll` for `ls -l`), then they would add it to the default bash_profile i think...

> Would you just not distribute this code? 
No, it is open...
If it becomes closed, the reason must be there are about >1000 person begin to laugh at my codes :)

The only purpose is that i want to make it funny (writing golang code in my way).

Brad Heller

unread,
Oct 1, 2016, 2:48:19 AM10/1/16
to Wang Yarco, golang-nuts
Not that I agree with the sentiment here, but just for discussion sake: Isn't this a (potentially) good candidate for code generation? Little complex, but...

Wang Yarco

unread,
Oct 1, 2016, 3:03:51 AM10/1/16
to golang-nuts, yarco...@gmail.com
Yes, maybe...But maybe after several days (months), i want other features added those are not suitable for code generation.
...So change it little by little would make me feel happy (Aha! i could customize it!), not do a separate generation tool that i would totally forget after several days.
Reply all
Reply to author
Forward
0 new messages