by stefanos82 · 4y ago · 0 comments
Personally I would have simplified its syntax a little bit more, if possible.
For instance, the following example code
main() {
sum := 0
for v in [5, 7, 11] index i //index is optional
{
if v == 11 { break }
sum += v
if sum > 20 { break }
print("$i: $v")
}
_OnBreak { //<-- must be immediately after loop
print("Index $i broke out of loop")
}
_OnComplete { //<-- Will not execute on break
print("Array is OK")
}
}
would have wrote it as follows: main() {
sum := 0
for v in [5, 7, 11] index i //index is optional
{
break if v == 11
sum += v
break if sum > 20
print("$i: $v")
}
_OnBreak :: print("Index $i broke out of loop") //<-- must be immediately after loop
_OnComplete :: print("Array is OK") //<-- Will not execute on break
}
I honestly like simple, well-written code that is easy to follow.I don't know if it'll make things more clear to you but curlys aren't nessicary when you use return/break/continue. I didn't write it because I didn't want to scare people off with the lack of curlys or confuse people on the front page
The `::` part looks nice. Would you want the statement to be forced on the same line? Or not like how C allows statements after `else`? As mentioned the compiler forces curly braces so it'll have to be forced to be on the same line as the on statement and I don't know if you'll find that to be a dealbreaker
I like the _OnBreak _OnComplete _OnEmpty . I think they simplify some loops and make those found_something variables go away. However I don't like that they start with an underscore. It feels so old (C and Python, which was designed at the end of the 80s.)
Case conventions are a little strange, something is lower case (main, for), something is camel case, something are upper case (methods?)
= := .= could be a little confusing. Why not only one? The compiler should know what to do because of the mut, out keywords.
About style: { sometimes leads a line, sometimes doesn't.
Early on _[A-Z] meant reserved variable so that's why it's currently _On. Many keywords are a single word and common enough that it shouldn't bother anyone that it's reserved. However I'm not great coming up with a style guide. On empty is two words, I have no idea how it should be written and everyone seems to have their own style.
Do you have a suggestion for the _On
keywords?> Why not only one? The compiler should know what to do because of the mut, out keywords
You noticed the out keyword? It's not recommended we only use that to interface with C code. Returning multiple variables is much better IMO (I won't speak for everyone). Accumulator and dynamic arrays are common enough that I didn't want to force people to write mut each time. It's simply `:=`
Let's suppose that in the future you want to add an argument to the break keyword to signal why the loop returned early. I use a string (btw, does the language have symbols / atoms?)
break "found"
break "eof"
break "invalid input"
Then you could have on "found"
on "eof"
on "invalid input"
with only one keyword. And on "complete"
on "empty"
> Returning multiple variables is much better IMOI agree but declaring a name for what you return is nice because it explains the purpose of the returned values. They could go outside the ()s.
stat(file) out length, created, modifiedIf it’s C like then the ExpressionStatement, umm…statement covers this; it’s how “if (foo=1) bar();” works (or leads to bugs depending on your point of view).
Also curious on how the automatic memory management works, might be on the website somewhere but I didn’t look past the first page.
I wrote some specifics in this thread over a few comments but that and the type system are complex. It can be a talk and writing short post probably will satisfy no one
What's confusing about that? Perl has that, I use it all the time.
For me, the problem is when my expression got long or if I call a function with multiple parameters. The more complex the line is the easier it is to not notice the `if`. Also I agree with what the other person said, it doesn't match the order if you read top down left to right
Perl is my main, and I never use that feature.
A for loop also doesn’t match what’s being executed. It’s s actually a do/while loop
(I would have preferred if the _OnBreak and _OnComplete statements was inside the for loop as that removes any ambiguity that it is part of it and effects the for loop).
However, `if v == 11 {break}` is definitely more readable than `break if v == 11`. If you are using curly braces as part of your syntax, and for blocks of code, it's better to use it with consistence. That can be confusing with `break {if v == 11}` as it breaks the syntax grammar, when you consider what break does.
the break, food out break out of the if block? Or somewhere else? It’s confusing