Live data from Hacker News

2 is a code smell

tech.puredanger.com

1–10 of 33 posts

Re: 2 is a code smell

#3
Cache: http://webcache.googleusercontent.com/search?q=cache%3Ahttp%...

tl;dr Clojure is awesome. And use

    (defn add-vectors [& vs]
     (vec (apply map + vs)))
instead of

    (defn add-vectors [va vb]
     [(+ (first va) (first vb)) (+ (second va) (second vb))])
since in Clojure code that operates on 1 or N things is usually better than some other fixed value. (Like 2.)

Re: 2 is a code smell

#6
What about sub-vectors? That smells like a 2 to me...

I'd rather call fold or foldr myself and KNOW how it handled more than 2 arguments. I'd rather do it for add-vectors too, just so it was consistent. You have to define primitives somewhere. Even if what you call elsewhere is some fluffy handle-everything function. At the very least, I wouldn't call it a smell.

Re: 2 is a code smell

#7
If a co-worker told me that my function was "code smell" because it took 2 arguments, I would tell him that he needs more important things to worry about.

Re: 2 is a code smell

#8

What about sub-vectors? That smells like a 2 to me... I'd rather call fold or foldr myself and KNOW how it handled more than 2 arguments. I'd rather do it for add-vectors too, just so it was consistent. You have to define primitives somewhere. Even if what you call elsewhere is some fluffy handle-everything function. At the very least, I wouldn't call it a smell.

I agree that it isn't necessarily a smell.

It really depends on the scope of the problem. Is this supposed to be a fully-functional addition function, or is this a throwaway helper function that the coder wrote because they were doing that specific operation many times, and they didn't want to type the entire thing out? If it's the first case, then it may be an issue. If it's the second, it's just poorly named, and not necessarily an issue at all.

Re: 2 is a code smell

#10
post #9

This is pretty much an instance of the good old "zero, one, infinity" rule. http://www.catb.org/jargon/html/Z/Zero-One-Infinity-Rule.htm...

This article restricts itself to a context where following "zero, one, infinity" results in simpler, more concise code. This is a good restriction. In general, following "zero, one, infinity" will often put you at odds with YAGNI.
Post reply on HN