2 is a code smell
tech.puredanger.com
2 is a code smell
1–10 of 33 posts
Re: 2 is a code smell
#2Re: 2 is a code smell
#3tl;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
#4Re: 2 is a code smell
#5Re: 2 is a code smell
#6I'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
#7Re: 2 is a code smell
#8What 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.
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
#9http://www.catb.org/jargon/html/Z/Zero-One-Infinity-Rule.htm...
Re: 2 is a code smell
#10This 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...