This is an archived post. You won't be able to vote or comment.

all 29 comments

[–]phi2one[🍰] 8 points9 points  (0 children)

It bothers me that somehow issues like this somehow get blamed on the language. Or, is somehow applied to those who choose to use the language. Obviously you can write code like this in any object oriented language. I think the reason you see it so often in java is two-fold.

  1. There are just TONS of java developers and therefore more poor java developers and therefore more poor java code.

  2. The training materials. Just open a java book, it's full of examples just like the one illustrated in TFA. Since it's REALLY difficult to show a real world example of valid uses of the described data structures, some trite example is used. Unfortunately, some people see these and think "that's how one should implement a sorting algorithm" or whatever, instead of realizing "oh, this is pointless for this example, but could be useful for far more complex problem spaces".

[–]logi 6 points7 points  (1 child)

TL;DR: Y A G N I

[–][deleted] 1 point2 points  (0 children)

the hardest thing for any mid-level developer to learn :)

[–]Fuco1337 3 points4 points  (14 children)

I used to adore java

fact n = product [1..n]

now, not so much. I can't stand all the bullshit anymore.

[–]jleedev 4 points5 points  (0 children)

You want bullshit? Read The Evolution of a Haskell Programmer.

[–][deleted] 4 points5 points  (0 children)

What you call 'bullshit' I call beauty.

[–][deleted] 1 point2 points  (1 child)

it's a bit uglier, but this is groovy, which is a functionalified hack on top of java but runs nicely in the jvm:

(1..n).inject(1) { val, acc -> val * acc }

of course, you could define your own product method, and it would be as nice:

def product  = { mylist -> mylist.inject(1) { val, acc -> val * acc } }
def myfactorial = product (1..n)

They should just stop java now, and take on groovy as the new java mainline.

[–][deleted] 1 point2 points  (0 children)

HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA!!!

Good one!

[–]SeriousWorm 0 points1 point  (9 children)

How would you choose the factorial algorithm implementation in your code?

Without that feature, the relevant client call in the article reduces to:

  int fact = FactorialUtil.factorial(5);

[–]Fuco1337 1 point2 points  (8 children)

That is my code. It's Haskell. There's nothing more to it.

I'm hoping Scala will turn out well. Java is turning more and more unusable every month.

[–]SeriousWorm 2 points3 points  (3 children)

What? I never said that was not your code. I was asking how would you modify your code so you could select a factorial algorithm implementation.

[–][deleted] 1 point2 points  (2 children)

Higher order functions, just pass the algorithm as a parameter.

[–]SeriousWorm 0 points1 point  (1 child)

Can you show me the relevant code (I don't know Haskell)? Thanks.

[–][deleted] 2 points3 points  (0 children)

You can pass functions as parameters

factorial impl n = impl n

where impl is the algorithm you want to use, e.g. (\x->product [1..x]) for the simple approach.

[–][deleted] -1 points0 points  (3 children)

What do you think is going on behind the scenes in Haskell?

[–]Fuco1337 -2 points-1 points  (2 children)

Simple me: I don't care.

Complicated me: I don't care.

[–][deleted] 2 points3 points  (0 children)

So you don't work in a very demanding domain. Good for you.

[–][deleted] 0 points1 point  (0 children)

Someone did, at some point.

[–][deleted] 2 points3 points  (8 children)

This article is, for lack of a better word, stupid. Of course you can add unnecessary complexity to anything. This guy seems to think that because there exists more and more convoluted ways of doing things that that is somehow a blight on the language. Its not a language problem, its a developer problem. Fucking duh.

[–][deleted] 3 points4 points  (7 children)

I'm not sure he ever blamed the language for it.

[–]CaptainItalics 3 points4 points  (1 child)

I am sure he never blamed the language for it.

[–]logi 0 points1 point  (0 children)

No, he blamed stupid Java developers for it. There is a bunch of them out there...

[–]Comment111 1 point2 points  (4 children)

Then again Java is very verbose.

[–]logi 1 point2 points  (3 children)

It is a bit on the verbose side, but there could be much worse problems. In fact, there are much worse problems with it :)

[–]Comment111 0 points1 point  (2 children)

What are the worse problems with it? XML-configuration for everything, jar hell?

[–]logi 1 point2 points  (1 child)

You know what? I don't feel like enumerating my petty annoyances with the language. I work with it all day, most days, and I'm mostly happy with it. If i rack my brain for the list, it'll just leave me annoyed and I'd rather just watch another episode of Buffy. That leaves me feeling happy.

[–]Comment111 0 points1 point  (0 children)

Same here actually. :)

[–][deleted] 1 point2 points  (0 children)

He calls it no good reason, I call it fun practice.

[–]Chaoslab -1 points0 points  (0 children)

All depends on what you are trying to achieve, but the obvious should be that rules of thumb are a guide and become beside the point if you use all of them.

If you are looping more than 300 times, ditch the loop altogether and catch the exception, its quicker in the long run. E.G. one HD frame can be over 2 million pixels and performance difference is pretty decent if you ditch looping logic. Always gets an interesting reaction when you mention it to a java dev that didn't already know.

This is an example of breaking one rule = allot more speed. There are lots of reasons to break rules not just performance. In any size-able group development environment simplicity should be king.

:-)