r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

Show parent comments

3

u/yogthos Feb 22 '15

Right, so not knowing what you were trying to do it's really hard to say what went wrong there. As I said, understanding how a macro works can often be non-trivial. There are tools like macroexpand that help you see what the resulting code will look like, but they can be difficult to reason about. This is the reason macro use is discouraged unless it's strictly necessary.

My point is that it's far more likely that you simply didn't understand what the code templated by the macro was doing than there being any actual problem with the compiler.

1

u/nickguletskii200 Feb 23 '15 edited Feb 23 '15

Sorry, but if at any point the compiler gives a NullPointerException instead of a proper message, there is something wrong with the compiler. Everything else does not matter.

1

u/yogthos Feb 23 '15

Well I guess there's something wrong with the Java compiler then and it's been around a bit longer than Clojure:

Object o = null;
o.getClass();
java.lang.NullPointerException: null

1

u/nickguletskii200 Feb 23 '15

That's a runtime error, not a syntax error. A better example would be this:

Object o =

And then the end of file, so the next token is null. The Java compiler, however, handles this.

1

u/yogthos Feb 23 '15

Now show me an equivalent of that in Clojure that makes the compiler return a nil and we'll talk.

1

u/nickguletskii200 Feb 23 '15

https://github.com/timmc/sscce-macro-readstring

I ran into something similar, but not exactly this. You can remove the first 4 lines in src/org/timmc/sscce/macro_readstring.clj and you will get something more like what I got.

1

u/yogthos Feb 23 '15

Except it runs fine with the latest version of Clojure:

git clone https://github.com/timmc/sscce-macro-readstring.git
Cloning into 'sscce-macro-readstring'...
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 33 (delta 9), reused 33 (delta 9)
Unpacking objects: 100% (33/33), done.
Checking connectivity... done.
~/s/tmp> cd sscce-macro-readstring/
~/s/t/sscce-macro-readstring> lein run
About to hit the bad code...
You're in this namespace: org.timmc.sscce.macro-readstring