arua-meta icon indicating copy to clipboard operation
arua-meta copied to clipboard

Verbosity of `this`

Open Qix- opened this issue 9 years ago • 5 comments

I want to enforce the use of this. in methods, but I recognize that it's very much a burden to type it out all the time.

However, Ruby has as a similar syntactical approach, the @ sign - which, when I used it in Coffeescript, I quite liked.

It's succinct, unique and easy for TextMate-based highlighters to show different colors for too.

Qix- avatar Jun 05 '16 05:06 Qix-

// @Polygn

Qix- avatar Jun 05 '16 05:06 Qix-

I think this could be handy... Would be easier to parse a single token @ rather than this as a string literal. I haven't used CoffeeScript but I have seen it, so yeah, the usage of using a @ could be quite [as you put it] succinct.

Now a question on the actual syntax of using @ rather than this, would it be used (in Arua) like this:

@.foo
@.bar

or more around the lines of

@foo # C++ equivalent: this.foo
@bar # C++ equivalent: this.bar

corbin-r avatar Jun 05 '16 05:06 corbin-r

@Polygn the second.

Qix- avatar Jun 05 '16 05:06 Qix-

@Qix- perfect! That now makes it even faster for the compiler rather than having the period, less text.

corbin-r avatar Jun 05 '16 05:06 corbin-r

But also less readable, I think.

If you're curious, all of the code I'm writing to test the lexer/parser is being pasted into a word document with no syntax highlighting - usually only done for things I'm not sure about (in terms of readability or maintainability). If it's not immediately obvious what it's doing, or if it requires a bunch of second looks, I am killing it.

This was the first thing I noticed. Look at it without syntax highlighting:

use math.*

on Foo be Bar
    fn something(foo i32, bar i32, qux f32) f32
        ret sin(bar as i32) * (6 * foo + @foo * bar * cos(foo as i32 * @qux) + qux) * 2

versus

use math.*

on Foo be Bar
    fn something(foo i32, bar i32, qux f32) f32
        ret sin(bar as i32) * (6 * foo + this.foo * bar * cos(foo as i32 * this.qux) + qux) * 2

I'm not sure which is more readable, but with syntax highlighting there's no mistake - this is much more readable since it'll be treated as a keyword.

Qix- avatar Jan 27 '17 03:01 Qix-