53 points · by wcrichton · 10y ago · 84 comments
> For brownie points, your compiler should explain why the programmer has encountered an error, and for the gold medal it should propose a solution.
This is exactly what we're trying to do with Eve. In one of the examples [2], I show an error that is met with a full explanation of what went wrong, a possible fix, and even a button that offers to fix the error.
On our philosophy toward errors, we've identified that they should be understandable (written in full plain English sentences), relevant (point to the root cause of the error, rather than incidental errors), and actionable (we provide the reason for the error, offer to automatically fix the error where possible, and teach the user why the error occurred and how to avoid it in the future.)
We're still in the early stages of handling errors, but this is at least how we're thinking about it.
https://msdn.microsoft.com/en-us/library/aa249862(v=vs.60).a...
Throw a unique error code in there, as well as a description on how to fix it.
foo();
^
Or something of the like. If the compiler knows the error, it knows what things might be missing. In the case of limited options it could predict and continue parsing. Then, with a more complex error, that error code is actually useful for googling or reviewing the compiler documentation.In terms of Boy Scouts, Python is the kid with strict dietary requirements who insists the other boys eat his crappy food, just because.
> 2to3 -w foo.py
Moreover much of the new Py3 syntax has been usable in 2.x for 10+ years with __future__ imports. There's little excuse for not taking advantage of it.BUT - Python is a great language for scripting. If you need to parse some stuff, produce a result ... Python is it.
The documentation bytes, I'm not a big fan of how it scales, packages are clumsy, deployment can be clumsy, but if you can get past those things, script away.
As far as brackets: in the long run I think it's better. I was very resistant to it at first. But then I came to prefer it.
I actually wish Java had a bracket-less option.
If Java had that, plus simpler file access, plus amazing array and string access ... man, that would be great.
Even though those are 'small things' - in reality, a lot of scripting code is filled with that, so it really adds up.
Going one step further ... maybe heretic - but having worked with a lot of Javascript ... I suggest that some loose data typing options would be great as well.
JSON in Java is a goddam pain. JSON and Javascript is seamless.
A lot of front-end programming is very data centric, but in the 'micro sense' i.e. passing around a lot of little bits of data. Also, it's highly event drive and async, which JS does well. So - also add more seamless async (Java Lambdas approach this) - and voila, Java could be better for UX type things as well.
But languages don't evolve very well, sadly :) it usually takes someone to come along and reinvent it using best practices and maybe a big company to support it, and it takes years to get to maturity.
Either that or to create a highly 'proprietary' version of something, a-la Microsoft.
That's really interesting to me. I feel almost exactly the same way about Perl. It has a heap of rough edges and things that are "imperfect" but when I need something done quickly (i.e a quick script to parse some text) I reach for perl. Strange how conceptually they are very different languages but have converged...
Jython is much older and more stable than Apache Groovy, and is bracket-less so there's no "almost but not quite" about it. It only exists for Python 2.x, not Python 3, which is a result of its stability.
Languages that have a more strict and less dynamic structure would likely have more difficulty working with JSON. On the other hand, give me an xsd and I'll generate some not awful Java. Consider the joys of JavaScript where one has to validate against an xsd.
Might I introduce you to Groovy? http://groovy-lang.org/json.html
Unlike with Javascript, JSON is not a subset of Apache Groovy syntax, which also makes it have difficulty working with JSON.
Paradox :)
"Perl is like vise grips. You can do anything with it but it is the wrong tool for every job." - Bruce Eckel
But yeah, the JVM is a great platform. But Java is inseparable from it, and Java isn't a great language.
So by "object identity," you mean doing equality comparisons with pointers instead of actually value equality. Just don't use eq. Use equal instead.
>FWIW, “just don't use eq” isn't good enough advice, because you can just mutate one of two supposedly “equal” objects to observe the difference between them
Yeah, that's true of every programming language in existance. What, do you want every equal object to be mutated, along with the one you mutated? That's just crazy talk.
>This is crucial to make functional programming work.
Well, if you're doing FP, than you aren't mutating values anyway. So just don't use eq.
At this point, your question utterly baffles me. Come back with a better explanation, or some examples of what you want, and I'll try to give you a better answer.
If your language does not support natively the set of rules you really like to enforce, you can still work in a style you like provided you establishes conventions and abstractions around it. So if you were actually interested in developing with, say, purely functional collections in Common Lisp, you would use the FSET[0] library:
(equalp (fset:bag 1 2)
(fset:bag 1 2))
T
(equalp (fset:bag 1 2)
(fset:bag 2 1))
T
That's exactly the same approach that people use when they do "C with classes", by reifying the abstraction into the host language.
Unsurprisingly, data-structures in FSET are implemented as Common Lisp structures, which allows having read-only slots as well as type specifiers.
Since we only want to have read-only slots, let's define a wrapper around defstruct (http://pastebin.com/30D6BnRg): (deftype tree () '(or node null leaf))
(deft leaf data)
(deft node
(left nil :type tree)
(right nil :type tree))
(equalp (node (node (leaf 3) (leaf 4)) nil)
(node (node (leaf 3) (leaf 4)) nil))
=> T
(compile nil
(lambda ()
(setf (data (leaf 3)) 0)))
; compilation unit finished
; Undefined function:
; (SETF DATA)
; caught 1 STYLE-WARNING condition
(compile nil
(lambda ()
(node "strange" "node")))
; caught WARNING:
; Constant
; "strange" conflicts with its asserted type
; (OR COMMON-LISP-USER::NODE NULL COMMON-LISP-USER::LEAF).
; See also:
; The SBCL Manual, Node "Handling of Types"
The above messages are caught while compiling the functions, not when calling them.
The language specification does not give you another way to mutate structure slots other than opt-in accessors. Granted, your implementation is probably smart enough to let you mutate it with (SETF SLOT-VALUE), but as a CL developer, you know that its bad to use it and that you should rely on accessors provided by the API.The advantage of Lisp at this point is that you can wrap your abstraction so tightly that it is indistinguishable from core features.
But maybe that's not enough for you, because there are not enough checks and you have your own idea of how things should work and you think you should do more compilation and less interpretation.
The compiler is available right here too, so you can even use it from your own compiler (during macroexpansion if you need) and do the analyzes you like. Or, you can even output a completely different executable file. Then you code a compiler in your new language because that's what grown-up languages do.
So, in order to do ML in Lisp, you develop your own DSL, an interpreter and later you bootstrap a compiler which is then self-sufficient to exist alone. That's roughly what happened decades ago: "Edinburgh LCF, including the ML interpreter, was implemented in Lisp"[1][2]. ACL2, an applicative, side-effect free subset of Common Lisp used for first-order theorem proving (Boyer-Moore), shares the same approach.
But the language that exists now, even though it does perfectly what it was designed for, is not Lisp anymore, and can't do exactly the things we actually like to do in Common Lisp.
[0] https://common-lisp.net/project/fset/Site/index.html [1] https://ocaml.org/learn/history.html [2] https://www.cl.cam.ac.uk/~mjcg/papers/HolHistory.pdf
> Reverent. Whether you belong to the Kingdom of Nouns or the Church of Lambda, be respectful of all faiths. Better yet, take the best of all worlds when designing your language (see: my previous post). Don't force users to pick one paradigm over the other, but rather be flexible enough to accommodate all walks of life.
If only.
But, that being said, I think all languages are coming around to adding first class functions.
Object-oriented languages have always been higher-order. Functional programming is great, but object-oriented languages have always had first-class procedures, whether they compute mathematical functions or not. And not all procedures compute mathematical functions in functional languages either.
What object-oriented languages lack is an emphasis on values, rather than the memory locations (aka object identities) that contain said values. The benefits of not worrying about object identities cannot be overstated: Removing the spurious distinction between memory blocks that hold equal values automatically endows the language with a richer equational theory that can be used both by language users (for reasoning about correctness) and language implementors (for optimization purposes).
It's a shame the clean rule isn't found in programming languages more. I really like low noise syntax of Python, Coffeescript, and Elm but it seems like it is not really being adopted.
Or, you know, just be memory safe.