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

-1

u/nickguletskii200 Feb 22 '15

Using macros is generally discouraged and vast majority of problems can be solved with regular functions. Beginners often get overexcited about using macros and that's a mistake in my opinion. Macros are a useful tool, but that's really not the main appeal of Clojure. If you look at popular Clojure libraries in the wild you'll see that there are very few macros in them. As the style guide says: don't write a macro if function will do[1] .

It wasn't enough in my case. Why would I waste my time on fighting macros if it were?

One of the main benefits I see using Clojure over Java is actually how rare null pointers happen, typically when doing Java interop. Since all the standard library functions handle nil values intelligently, they simply bubble up to the top in most cases. Instead of having to pepper null pointer checks all over the place, you can simply check for a value at the end of the transformation.

But the compiler still nullpointed.

Again, I'm not sure what you mean by "fix the compiler". The compiler works exactly as it's supposed to, but you have to understand the intricacies of the language in order to use the most advanced features.

Throwing NullPointerExceptions instead of syntax errors isn't "working as it is supposed to" in my book.

1

u/yogthos Feb 22 '15

It wasn't enough in my case. Why would I waste my time on fighting macros if it were?

There's nothing that macros let you do that can't be done without macros. They're a way to template code when you see repetitive patterns. You still haven't described what it is that you were trying to do in the first place.

But the compiler still nullpointed.

I'm not sure what you mean by "compiler nullpointed", are saying you crashed the compiler. I've certainly never seen that happen myself.

Throwing NullPointerExceptions instead of syntax errors isn't "working as it is supposed to" in my book.

Again, perhaps you could actually described exactly you did and how you got a null pointer. Perhaps you can paste your code. I have a rather hard time believing that you managed to crash the compiler.

1

u/nickguletskii200 Feb 22 '15

Again, perhaps you could actually described exactly you did and how you got a null pointer. Perhaps you can paste your code. I have a rather hard time believing that you managed to crash the compiler.

I don't have the code anymore, that happened 1.5 years ago and I pretty much threw away the project.

There's nothing that macros let you do that can't be done without macros. They're a way to template code when you see repetitive patterns. You still haven't described what it is that you were trying to do in the first place.

Yes, but it would be considerably harder to do. If I recall correctly, macros in Clojure are actually implemented in Clojure, so yes...

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.

→ More replies (0)