I may be perceiving this wrong, but it appears to me that in more recently newly created languages lexical scoping and explicit variable declaration are conspicuously absent. In the face of these features' positive effects on software quality and maintainability, i have to suspect that their lack is usually a conscious decision.
However, probably due to my inexperience in creating programming languages, i cannot think of reasons for this kind of decisions.
I'm no language designer either, but I would guess that since Crystal wants to be 100% type inferred, they feel that having to type "var" or "let" is just boilerplate.
Even in type inferred languages they serve some use, namely in avoiding mis-typed variable names. Languages which require "var" make a distinction between the intent of declaring a new variable vs setting the value of an existing variable, and so are able to catch instances where the programmer tries to set a non-existent variable.
Features like Scala's implicit parameters could be argued to be a kind of "dynamic scope". True, the language is lexically scoped and most code is written expecting that, but it does allow you to "opt out" of this scoping mechanism and look for values to be specified in the environment.
I'll premptively add a bit of precision before a pedant comes along: my is lexical all the way; our defines a lexical binding over a global variable, and local defines a dynamic binding (of lexical extent) over a global.
Don't we already have more than enough programming languages? I looked through the intro and this language introduces nothing new. Your time would have been better wasted on building a framework for an already established language. Sorry for putting you down, consider it tough love
Not even close. There is an incredible amount of room for innovation and research in programming languages. You do not have to learn this or any of them and can continue to program in whichever language is at the peak of commercial success at the moment.
But it is important that we continue to try new things and make progress in this area.
Unfortunately this particular project does not seem to push many boundaries.
> Don't we already have more than enough programming languages?
No.
> I looked through the intro and this language introduces nothing new.
Its individual features aren't unique. The combination of them in one language seems to be somewhat new. What language do you see that it is redundant with?
We have far more frameworks than we do languages, also there is a ton of knowledge to be gained by going through the steps of designing and implementing a programming language.
As a picky individual, I prefer this variation of languages over a few but established ones. It takes an hour to fully learn another new programming language, and it adds more excitement and comfort to programming.
Programming languages in the modern sense are different to programming languages of, say, 20 yrs ago. If a language sits atop the JVM or generates Javascript, it's a "new programming language" in the modern sense but probably wasn't considered one previously. And nowadays, a "programming language" needs a visual IDE or plugin, rather than just a syntax, to be considered more than just a toy.
"Just fine" is papering over the fact that people get tripped up by this in Python all the time – sometimes you need to use the `global` or `nonlocal` statements to resolve the ambiguity.
If you search for UnboundLocalError on StackOverflow, there are 918 results. Not all of them are due to this particular scoping ambiguity, but many of them are.
It's a mistake even in Python. It makes typos harder to catch. And a visible distinction between variables that change and values that don't makes code much easier to reason about.
I am excited to see new programming languages like this. I can name 100 duck typed, interpreted, GC'd languages, but only half a dozen native compilers for modern languages. Native binaries are much easier to deploy on consumer's desktops than bytecode or source code requiring >50MB VMs, and the code tends to be much more rigid and rigorous with a statically typed language like this.
I haven't downloaded the compiler yet, but here are a few things I like after reading the documentation.
- The C bindings are nice and simple in Crystal, with full support for structures and data types,
- "Globally named" symbols are a really great idea, especially in native binary when compiled to Int32's,
- OOP support seems polished with full support for encapsulation,
- Basic control structures and scope are also polished and familiar, while leaving beind the nasty parts from Ruby (i.e. `for do` vs `for`, Matz's regret for `do ... while`, etc)
- --hierarchy. Why haven't I seen a compiler support this by now?
A final point: "Everything is an object" and C-like efficiency seems paradoxical, but I'll look more into this. Objects may be abstracted by the compiler, but once compiled behave like any ole' statically typed system.
I was referring to the veil of deprecation over `do end while` by Matz's comment that you've linked, but as long as Crystal endorses it, is it fine with me.
We actually started by copying ruby's syntax and semantic, including the `do end while`. But a long time ago we started to diverge from it. We are also not sure about this "feature" and we still have time to remove it from the language :-) . It's true that a simple `while ... break if ... end` is enough.
Edit: I also misunderstood the comment. In Crystal `exp while cond` and `begin exp end while cond` are the same.
There are a couple of features I'd love Crystal to have, but I might be in the minority. One, immutability by default, or rather, make immutability more the rule than the exception. Two, type checked named parameters/keyword arguments. Yes they are verbose, but they make it much more clear what the code is doing upon 2nd, 3rd,..... 100th reading than something like MyObject.method(a, b, 1, zurb, foobar, false, -1, "bob"), where the order is important and the variables don't ned to be well named.
Swift, Kotlin, and Scala seem to be the only significant languages to get both features pretty close to what I'd want. Otherwise, I don't see much in the language space that scratches that itch.
Those three languages seem to be the closest to getting "the future" right when it comes to the "next generation" of languages - functional, object oriented, type checked and compiled languages with a bit of dynamic checking/inference for programmer convenience. Other languages seem to be too much in other particular directions to get the benefit of different styles where it makes sense.
I had high hopes for Mirah, but it hasn't really evolved the way I'd hoped.
I don't know if my notion for a language is the right direction for Crystal, but I'd love it if someone came along and made my "perfect language" for me. It'd be one less thing to build myself.
Curious, I've been hearing a lot lately about functional languages and immutability and wasn't quite sure how it worked. I agree with it in premise but it seems like all these immutable data structures introduce massive overhead.
What is going on behind the scenes when I modify a single value in an array with 10k members? Surely it's not going to create an entirely new array.
Or, you might do something where you have a list of pointers, and you point at a different value instead of mutating an existing value.
I haven't dug into the details of how immutable data structures can be made to work efficiently, but part of the charm is that in many cases you don't mutate the array at all. What I mean is, there are certain behaviors around mutation that programmers do because they can.
When you take away the ability to mutate data, you design differently and without side effects. All of a sudden testing becomes easier, faster, cheaper for large parts of your codebase. You have simpler solutions that are potentially easier to reason about because the complex (and sometimes elegant) solutions aren't so readily available.
A few talks that are around this style of thinking:
Boundaries are good, values are good, simple things that work together are good. The more we can take the good parts and form them together into a cohesive language/framework/platform, the better our software will be.
This book is more or less the definitive book on functional persistent data structures. More about how to design and reason about them, then a collection book.
> Curious, I've been hearing a lot lately about functional languages and immutability and wasn't quite sure how it worked. I agree with it in premise but it seems like all these immutable data structures introduce massive overhead.
There is some seemingly inherent overhead for certain data structures. On the other hand it allows for structural sharing, and plays more nicely with concurrency and whatnot. Suffice it to say that you'd be wise to design your immutable (persistent, specifically) data structures very differently to how you would design your regular imperative data structures. There was a famous PhD dissertation - now a book - on the topic. You'll find it easily enough if you search for it.
Yes, immutable data structures seem very inefficient. But they're implemented in a more clever way than to just take regular imperative data structures and copying for every "update" instead of directly mutating.
> What is going on behind the scenes when I modify a single value in an array with 10k members? Surely it's not going to create an entirely new array.
It would be unwise to use a huge array (in the usual sense - contiguous memory) like that to begin with. You'd probably have an "array" that is more in the shape of a tree, which facilitates more efficient "updates".
Although Groovy 2 brought type inference it isn't used much, so Groovy's main use case is as a dynamically typed language as was originally intended by its creator.
43 comments
[ 3.3 ms ] story [ 103 ms ] threadHowever, probably due to my inexperience in creating programming languages, i cannot think of reasons for this kind of decisions.
What could these be?
I'm not sure I can think of any languages at all that have dynamic scoping since the early lisps.
[1] http://www.perlmonks.org/?node_id=66677
But it is important that we continue to try new things and make progress in this area.
Unfortunately this particular project does not seem to push many boundaries.
https://news.ycombinator.com/item?id=8612359
I agree. We have tons of programming languages but if anything, this can exist as "Art" or study.
Don't we already have more than enough frameworks for established languages? :\",
No.
> I looked through the intro and this language introduces nothing new.
Its individual features aren't unique. The combination of them in one language seems to be somewhat new. What language do you see that it is redundant with?
https://docs.python.org/3/reference/simple_stmts.html#global
https://docs.python.org/3/reference/simple_stmts.html#nonloc...
Classic example: http://stackoverflow.com/questions/9264763/unboundlocalerror...
If you search for UnboundLocalError on StackOverflow, there are 918 results. Not all of them are due to this particular scoping ambiguity, but many of them are.
I haven't downloaded the compiler yet, but here are a few things I like after reading the documentation.
- The C bindings are nice and simple in Crystal, with full support for structures and data types,
- "Globally named" symbols are a really great idea, especially in native binary when compiled to Int32's,
- OOP support seems polished with full support for encapsulation,
- Basic control structures and scope are also polished and familiar, while leaving beind the nasty parts from Ruby (i.e. `for do` vs `for`, Matz's regret for `do ... while`, etc)
- --hierarchy. Why haven't I seen a compiler support this by now?
A final point: "Everything is an object" and C-like efficiency seems paradoxical, but I'll look more into this. Objects may be abstracted by the compiler, but once compiled behave like any ole' statically typed system.
Huh? Do you mean http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/...? It's still there: http://crystal-lang.org/docs/syntax_and_semantics/while.html
Edit: Ah, the behavior of the while modifier is different in Crystal.
Edit: I also misunderstood the comment. In Crystal `exp while cond` and `begin exp end while cond` are the same.
https://github.com/manastech/crystal
https://github.com/kostya/benchmarks
Here's another one:
https://github.com/nsf/pnoise
And then in the samples directory ( https://github.com/manastech/crystal/tree/master/samples ) there are some more but without time results (but you can try them yourself).
Nice work.
Swift, Kotlin, and Scala seem to be the only significant languages to get both features pretty close to what I'd want. Otherwise, I don't see much in the language space that scratches that itch.
Those three languages seem to be the closest to getting "the future" right when it comes to the "next generation" of languages - functional, object oriented, type checked and compiled languages with a bit of dynamic checking/inference for programmer convenience. Other languages seem to be too much in other particular directions to get the benefit of different styles where it makes sense.
I had high hopes for Mirah, but it hasn't really evolved the way I'd hoped.
I don't know if my notion for a language is the right direction for Crystal, but I'd love it if someone came along and made my "perfect language" for me. It'd be one less thing to build myself.
What is going on behind the scenes when I modify a single value in an array with 10k members? Surely it's not going to create an entirely new array.
Or, you might do something where you have a list of pointers, and you point at a different value instead of mutating an existing value.
I haven't dug into the details of how immutable data structures can be made to work efficiently, but part of the charm is that in many cases you don't mutate the array at all. What I mean is, there are certain behaviors around mutation that programmers do because they can.
When you take away the ability to mutate data, you design differently and without side effects. All of a sudden testing becomes easier, faster, cheaper for large parts of your codebase. You have simpler solutions that are potentially easier to reason about because the complex (and sometimes elegant) solutions aren't so readily available.
A few talks that are around this style of thinking:
https://www.destroyallsoftware.com/talks/boundaries
https://www.youtube.com/watch?v=WpkDN78P884
https://www.youtube.com/watch?v=tq5SQ4W3gRI
http://www.infoq.com/presentations/Simple-Made-Easy
Boundaries are good, values are good, simple things that work together are good. The more we can take the good parts and form them together into a cohesive language/framework/platform, the better our software will be.
http://www.amazon.com/Purely-Functional-Structures-Chris-Oka...
There is some seemingly inherent overhead for certain data structures. On the other hand it allows for structural sharing, and plays more nicely with concurrency and whatnot. Suffice it to say that you'd be wise to design your immutable (persistent, specifically) data structures very differently to how you would design your regular imperative data structures. There was a famous PhD dissertation - now a book - on the topic. You'll find it easily enough if you search for it.
Yes, immutable data structures seem very inefficient. But they're implemented in a more clever way than to just take regular imperative data structures and copying for every "update" instead of directly mutating.
> What is going on behind the scenes when I modify a single value in an array with 10k members? Surely it's not going to create an entirely new array.
It would be unwise to use a huge array (in the usual sense - contiguous memory) like that to begin with. You'd probably have an "array" that is more in the shape of a tree, which facilitates more efficient "updates".