←back to thread

My Foray into Vlang

(kristun.dev)
87 points Bogdanp | 6 comments | | HN request time: 0s | source | bottom
1. anon-3988 ◴[] No.45082438[source]
I fail to understand why every single new language tries to be "funny". Lets take a look at this example:

module main

struct Language { pub mut: score int = -1 name string @[required] }

fn (lr []Language) total() int { mut total := 0 for l in lr { if l.score > 0 { total += l.score } }

return total }

fn (lr []Language) average() int { return lr.total() / lr.len }

fn main() { racket := Language{98, 'racket'} // Simple arrays too! langs_arr := [racket, Language{102, 'ocaml'}] println(langs_arr) println(langs_arr.total()) println(langs_arr.average()) }

Remove

1. Whatever this is "fn (lr []Language) total() int {", why is there an ability to define a special function to an array? How do I know what overload is being used? If I change something from map to vector, how do I know there's nothing else that changes? Member function is just a sugar over regular functions? Great, remove member functions.

2. Why allow this? "racket := Language{98, 'racket'}" ? Why implicitly depend on ordering of parameter? Just use Language { .score = 98, .name = "racket", } Confusing order of evaluation? Great, just force it to be assigned exactly the same as the definition and force ordering that way.

3. Why remove the parenthesises " if l.score > 0 {"? In fact, I would even reject code that assumes any integer != 0 is True. Nope, you have to do the exact check every time. No more if (x) { }

4. Why allow default parameter? Why needing special syntax for @required?

I just want a very limited C with GC, pattern matching and algebraic data types. I don't even need generics.

replies(4): >>45082548 #>>45082560 #>>45082799 #>>45082962 #
2. torginus ◴[] No.45082548[source]
Everything you complain about here is straight-up Go syntax.
replies(1): >>45083385 #
3. ◴[] No.45082560[source]
4. frou_dh ◴[] No.45082799[source]
Just because you have reverence for C and C syntax, doesn't mean others have to. What is "funny" is subjective.
5. boxed ◴[] No.45082962[source]
The paren for the argument to if in C is just there to be able to omit {}. Which is one of the most stupid things in C. Add two characters for ALL if statements to avoid two characters for >1% of if statements. That is a mathematically certain loss.
6. ohdeargodno ◴[] No.45083385[source]
Mind you, that doesn't prevent Go's syntax from being terribly stupid. They just happen to line up on stupid choices.