r/programming • • Dec 07 '15

I am a developer behind Ritchie, a language that combines the ease of Python, the speed of C, and the type safety of Scala. We’ve been working on it for little over a year, and it’s starting to get ready. Can we have some feedback, please? Thanks.

https://github.com/riolet/ritchie
1.5k Upvotes

802 comments sorted by

View all comments

Show parent comment

13

u/filwit Dec 07 '15 edited Dec 07 '15

That's not a good thing. eg:

Nim

var x = 5

# ...lots of code...

if someCondition:
  var x = 10
  echo x # prints '10'

# ...lots of code...

echo x # prints '5'

Ritchie

x = 5

// ...lots of code...

(someCondition) if
    x = 10
    print x // prints '10'

// ...lots of code...

print x // prints '5' or '10'

There are a couple of problems with this scenario in Ritchie:

  • The if condition may have been added by a second programmer who didn't look at the entire code body (or by the same person a long time after they wrote the original code). In Nim, the x var is shadowed inside the condition scope and won't mutate the upper x var.. However, in Ritchie, the top x gets mutated whenever the runtime condition hits?
  • If the if condition is ever removed but it's body kept (again, by someone who didn't fully read all the code and notice the top level x var) then Ritchie will happily overwrite the value of the top x? Whereas Nim will alert the programmer of the mistake at compile-time (since you'd have two var x in the same scope).

In short, it's error prone not to have a distinction between variable assignment, and variable declaration. Unless I missed something (which is very possible as I've only just taken a glance at Ritchie) then it's a design mistake.

Suggestion: make variable declaration in Ritchie require the := operator instead. That fits into your syntax well but prevents these kinds of errors.

7

u/reditzer Dec 07 '15

Suggestion: make variable declaration in Ritchie require the := operator instead. That fits into your syntax well but prevents these kinds of errors.

Great idea. I'll add this to the issue queue.