News for hackers. Stuff that matters.
Re:Pyret – A language exploring scripting and functional pro... by danso on Thursday December 15, 2016 @12:12PM (#13186164)
Example from the OP:

        fun to-celsius(f):
          (f - 32) * (5 / 9)
        end

What's the justification for allowing the use of hyphens/dashes in reference names, when underscores would seemingly provide the same purpose? One of the most common problems I notice in newbie code is inconsistency in using whitespace, e.g. `a-b` vs `a - b`, though in that situation, for Python and virtually every other language I've used, those both result in subtracting b from a. But in Pyret, it seems that `a-b` would be interpreted as a reference? That seems needlessly confusing for no benefit in readability over using snakecase.

Beginners frequently have issues with grammar, that is, they are pretty much unaware of it when trying to figure out the many other things they have to learn about programming. Even in SQL, I forget that it must be quite confusing for beginners to parse out the meaning of the `` in something as simple as:

     SELECT mytable.*, (a * b) AS myproduct, 
          COUNT(*) AS the count
     FROM mytable ...
Doesn't seem worth it to make the hyphen, which is so frequently associated with subtraction and negative numbers, have just a decorative meaning when used between word tokens (as opposed to subtraction of values represented by variables).
Re:Pyret – A language exploring scripting and functional pro... by jswrenn on Thursday December 15, 2016 @12:22PM (#13186255)
Pyret inherits hyphens-in-identifiers from Scheme/Racket. One of Pyret's largest users, Bootstrap [1], has long-used a dialect of Scheme, and has recently introduced a curriculum that uses Pyret. For these users, "virtually every other language" allows for hyphens in identifiers.

Scheme mitigates the spacing issue with s-expressions. Pyret attempts to mitigate it by enforcing that operators should be separated from their operand with at least one space.

(Disclosure: I am an occasional developer of Pyret.)

[1] http://www.bootstrapworld.org/

Re:Pyret – A language exploring scripting and functional pro... by eridius on Thursday December 15, 2016 @01:28PM (#13186847)
Scheme and Racket are both LISPs, with very different syntax. Hyphens in identifiers aren't a hazard, because binary operators don't go between two other identifiers, and operators must be separated with spaces, e.g. subtraction looks like `(- 2 1)` instead of `2 - 1`. This means that using hyphens in identifiers is quite safe.

But Pyret is using more traditional syntax, where binary operators go between their operands, e.g. `2 - 1`, which means using hyphens in identifiers is a hazard as the parent comment describes.

Re:Pyret – A language exploring scripting and functional pro... by simplify on Thursday December 15, 2016 @01:41PM (#13186965)
The problem is overblown. It's not going to cause any deep, hard-to-debug errors. If you accidentally type `a-b`, you'll get an error message that says "a-b is not defined". Fix it and you're done.
Re:Pyret – A language exploring scripting and functional pro... by samcal on Thursday December 15, 2016 @01:56PM (#13187109)
While I agree that the problem is not a very big deal, I think that you might be surprised how difficult understanding compiler errors can be for newcomers.
Re:Pyret – A language exploring scripting and functional pro... by skrishnamurthi on Thursday December 15, 2016 @02:40PM (#13187536)
The Pyret design team has done perhaps the most in-depth research into error messages of anyone [e.g.: http://cs.brown.edu/~sk/Publications/Papers/Published/mfk-me..., http://cs.brown.edu/~sk/Publications/Papers/Published/mfk-mi...]. We're deeply aware of the effect of error messages. This isn't a problem.
Re:Pyret – A language exploring scripting and functional pro... by CodeMage on Thursday December 15, 2016 @02:13PM (#13187272)
I regard that as a valuable teaching moment: "This, kids, is a great example of what you'll have to deal with all the time. Computers are not smart and neither are compilers. Forget a semicolon or some whitespace, and it's your job to clean up the mess after your compiler shits its bed."
Re:Pyret – A language exploring scripting and functional pro... by dkersten on Friday December 16, 2016 @06:31AM (#13192535)
Having been a tutor of first-year beginner programming students many years ago, my experience has been that its not quite as simple as this.

The number of people who forgot even the most simple syntax rules towards the end of the semester, even after having shown them during each lab session, was surprisingly high.

You tell them that the computer is super dumb and pedantic and they understand this. So you tell them the rules (semi colon at the end of line perhaps) and they understand. Then an hour later and they're staring blankly at the screen wondering why they got the exact same error again.

Obviously not all students are like this and almost all did get it after a while, but you'll be repeating your statement to them enough times that you wished the language didn't have whatever warts is causing the confusion.

I found Java particularly bad, because you have to tell beginners to ignore 90% of the hello world program (class ... public static void main ... - you have to tell them "hey, ignore class, public, static, void etc for now, we will cover it later"), which isn't satisfying at all and in my experience caused more confusion still...

Yes, you've got to treat it as a learning experience, but the students usually see it as a roadblock and cause of frustration. Often one that doesn't make sense to them and they question why its even a thing. ("why can I use '_' in identifiers and not '-'?", not too hard to explain of course but its yet another bit of incidental complexity to them)

Re:Pyret – A language exploring scripting and functional pro... by spacemanmatt on Thursday December 15, 2016 @02:35PM (#13187474)
I don't recall having real trouble with category errors like this as a beginner. Do you think that is a serious problem?
Re:Pyret – A language exploring scripting and functional pro... by cglouch on Thursday December 15, 2016 @12:23PM (#13186267)
Well as dumb as it sounds, one reason to allow hyphens instead of requiring underscores is that the former takes one keystroke to type, whereas the latter takes two. This is kind of nice when dealing with longer function names.

It's also worth noting that pyret requires spaces between all math operators, not just subtraction. In other words, 3+4 is not valid; you would need to type 3 + 4. So at least it's internally consistent in that sense.

Re:Pyret – A language exploring scripting and functional pro... by danso on Thursday December 15, 2016 @12:32PM (#13186343)
Not dumb at all...it's just that assuming that we spend more time re-reading code than we do in the initial writing of it, saving the keystroke from hyphen-to-understroke seems like premature optimization :).

Good to know that Pyret requires spacing between the other operators. That does help a lot, and an argument could be made that it forces folks to not do `a-b` when they mean `a - b`.

Re:Pyret – A language exploring scripting and functional pro... by yoz-y on Thursday December 15, 2016 @02:37PM (#13187508)
Personally I find that hyphen-separated identifiers are more readable than when they have underscores. When dabbling in perl6 I got accustomed to then very quickly. And forcing people to put spaces around binary operators is definitely a plus.
Re:Pyret – A language exploring scripting and functional pro... by skrishnamurthi on Thursday December 15, 2016 @02:37PM (#13187510)
It's not dumb at all. It's one of the things we had in mind when we designed the syntax!
Re:Pyret – A language exploring scripting and functional pro... by skrishnamurthi on Thursday December 15, 2016 @02:39PM (#13187524)
If you're used to the syntax of identifiers from Lispy languages, you'll love the hyphens in the names (what some people call kabob-case). Because the syntax requires spaces between operators, there is no ambiguity. We have had several hundreds of Pyret programmers and there has literally never been any confusion about the syntax: in fact, people didn't even _notice_ they were using `-` in two different ways until it was pointed out to them. Empirical data rocks!
Re:Pyret – A language exploring scripting and functional pro... by cygned on Thursday December 15, 2016 @12:31PM (#13186337)
As a Clojure programmer, I learned to love hyphens, so much more readable. But since Clojure is a Lisp, is does not suffer this whitespace problem/confusion.

    (- a b)
Re:Pyret – A language exploring scripting and functional pro... by kazinator on Thursday December 15, 2016 @01:14PM (#13186724)
An infix language could also require whitespace around operators, so that a-b could be a an identifier.

Like in a Lisp infix macro: (infix (a + b * c) / d).

This kind of thing is quite habitable: we hardly lose sleep over (3.4) the list of one float versus (3 . 4) the dotted pair of integers.

Re:Pyret – A language exploring scripting and functional pro... by skrishnamurthi on Thursday December 15, 2016 @05:40PM (#13189308)
We're discussing an infix language that does exactly that. In Pyret, binary operators must be surrounded by spaces. Therefore, `a-b` is not ambiguous.
Re:Pyret – A language exploring scripting and functional pro... by brudgers on Thursday December 15, 2016 @03:45PM (#13188223)
I'd say that white space requirements around operators even seems implicitly consistent with the Pythonic idiom of semantic white space and the Pythonic dictum of only one way to do things.
Re:Pyret – A language exploring scripting and functional pro... by skrishnamurthi on Thursday December 15, 2016 @09:46PM (#13190681)
Python has many ways to do just about everything (e.g., list comprehensions are completely redundant). It's a nice marketing slogan, though.
Re:Pyret – A language exploring scripting and functional pro... by brudgers on Thursday December 15, 2016 @10:18PM (#13190803)
Yes, there's even two Pythons.
Re:Pyret – A language exploring scripting and functional pro... by kpil on Thursday December 15, 2016 @01:10PM (#13186682)
I'd say there is some room for confusion, even if it's not in the grammar.

I have spent quite some time chasing bugs of the type (- a -1) where the second minus ended up there because of either a copy/paste-error or a brain fart due to the original expression was a - 1...

Re:Pyret – A language exploring scripting and functional pro... by wolfgang42 on Thursday December 15, 2016 @01:22PM (#13186792)
I'm not sure how (- a - 1) would work, unless you've named something "-"?
Re:Pyret – A language exploring scripting and functional pro... by Grue3 on Friday December 16, 2016 @05:09AM (#13192233)
- is a function. Because Closure is a Lisp1, substraction function being passed as an argument like that is very probable. In Common Lisp you'd pass #'-, so it's clear that it's a function being passed.
Re:Pyret – A language exploring scripting and functional pro... by FrancoDiaz on Thursday December 15, 2016 @04:48PM (#13188771)
I love hyphenated symbols. It's so much easier to read than camel or Pascal-casing. As another poster pointed out, using whitespace between subtraction variables and the minus sign is just a non-issue in practice.
Re:Pyret – A language exploring scripting and functional pro... by Avshalom on Thursday December 15, 2016 @12:49PM (#13186488)
Part of the reason whitespace is inconsistent around operators is because nothing about most languages forces you to care. It's a lot like case sensitivity in that regard.
Re:Pyret – A language exploring scripting and functional pro... by pierrebai on Thursday December 15, 2016 @01:39PM (#13186943)
There's more to it; making whitespace significant makes it harder to read in print and when presented with non-monospace fonts on-screen. Even without these caveat, it's still a bit harder to visually process. It's like the = vs == problems. It's easy to get right, you almost always get it right, but it's close enough to cause errors and requires extra concentration effort.

Other lisp-ism: gratuitous abbreviations. Is 'lam' instead of 'lambda'. Given its teaching claim, that's two layer of understanding required of students: to know what a lamba is and to connect that lam stands for lambda.

Re:Pyret – A language exploring scripting and functional pro... by Avshalom on Thursday December 15, 2016 @01:57PM (#13187124)
it's kind of interesting because originally my comment was a stronger defense of hyphens then when I compared it to Case sensitivity I actually back tracked.

Ada for instance specifically considered then rejected case sensitivity because they had a (at least one) study that said case sensitivity was a source of errors.

I don't know how well instrumented the pyret courses are but I would be very if they have studies on this.

Re:Pyret – A language exploring scripting and functional pro... by skrishnamurthi on Thursday December 15, 2016 @09:48PM (#13190685)
Pyret's implementation is by design very privacy-preserving (we don't just quietly make a copy of everybody's code, people have to explicitly share copies — we don't want to freak out students by surveilling them). But we do have some data that students have given us. In those data, we do not find evidence of case-sensitivity being a problem.
Re:Pyret – A language exploring scripting and functional pro... by Ericson2314 on Thursday December 15, 2016 @03:16PM (#13187889)
Pyret enforces what everyone agrees is good style anyways, and consistently requires whitespace in other places similar-looking languages don't.

This therefore is perfectly natural; non-programmers are used to using spaces to delimit words and this is simply doing the same for tokens.

Re:Pyret – A language exploring scripting and functional pro... by davexunit on Thursday December 15, 2016 @12:43PM (#13186440)
Hyphens are much better for names than underscores, and easier to type.
Re:Pyret – A language exploring scripting and functional pro... by dragonwriter on Friday December 16, 2016 @12:19PM (#13194855)
> What's the justification for allowing the use of hyphens/dashes in reference names, when underscores would seemingly provide the same purpose?

Hyphens commonly are used to join words into compoubds in English, underscores are not; the latter are used in many programming languages as a result of the fact that not allowing hyphens to serve that role when they also serve as an operator in other contexts simplifies automated parsing (and allows syntax that supports more compact expressions, and there was a time when bytes of source code had a greater cost than they do now.)

Re:Pyret – A language exploring scripting and functional pro... by xapata on Thursday December 15, 2016 @01:25PM (#13186823)
People mess up the other way as well, thinking "a-b" is a valid identifier in Python.
Re:Pyret – A language exploring scripting and functional pro... by juliendorra on Thursday December 15, 2016 @12:15PM (#13186195)
On the other end, I love that Calca (mac and iPhone app and language) allows to use spaces in function or variable names. It's so natural.