Live data from Hacker News

Code Smells: Iteration

blog.jetbrains.com

1–10 of 95 posts

Re: Code Smells: Iteration

#2
At the risk of sounding arrogant, isn't this a bit obvious?

To me, code smells are more about spotting when someone's been forced to do something a bit weird and convoluted. It's possibly the cleanest solution available given the immediate context, but this is actually a symptom (or "smell") that something is wrong with the wider design of the system.

This article seems more about detecting choices around data structures which are bad in any context and have no real link to the overall system design.

Re: Code Smells: Iteration

#3
I like this kind of article not necessarily because it's revolutionary or groundbreaking (because it's not), but because it serves as a helpful reminder sometimes, and can help stick an "observation bias" bug in my brain to notice more often the sorts of examples it calls out.

Re: Code Smells: Iteration

#4
post #2

At the risk of sounding arrogant, isn't this a bit obvious? To me, code smells are more about spotting when someone's been forced to do something a bit weird and convoluted. It's possibly the cleanest solution available given the immediate context, but this is actually a symptom (or "smell") that something is wrong with the wider design of the system. This article seems more about detecting choices around data struct…

It's obvious to some of us, but not all of us. I see things way worse than this on a fairly regular basis.

Re: Code Smells: Iteration

#5
post #2

At the risk of sounding arrogant, isn't this a bit obvious? To me, code smells are more about spotting when someone's been forced to do something a bit weird and convoluted. It's possibly the cleanest solution available given the immediate context, but this is actually a symptom (or "smell") that something is wrong with the wider design of the system. This article seems more about detecting choices around data struct…

Naw man, code smells are anything that when you look at code and you wrinkle your face like you would if a cow farted right in front of it.

Re: Code Smells: Iteration

#6
post #2

At the risk of sounding arrogant, isn't this a bit obvious? To me, code smells are more about spotting when someone's been forced to do something a bit weird and convoluted. It's possibly the cleanest solution available given the immediate context, but this is actually a symptom (or "smell") that something is wrong with the wider design of the system. This article seems more about detecting choices around data struct…

It's obvious to anyone with a CS (or similar) degree, but may not be to someone who is learning to code from various tutorials. Having hints like this in your IDE can greatly improve the quality of your code and help you learn.

Re: Code Smells: Iteration

#7
The author proposes using data structures that use hashing without even mentioning the necessity of having a hash function and immutable data for the hashed objects, because in their case they were basically just using strings.

It isn't always that easy.

Re: Code Smells: Iteration

#8
post #2

At the risk of sounding arrogant, isn't this a bit obvious? To me, code smells are more about spotting when someone's been forced to do something a bit weird and convoluted. It's possibly the cleanest solution available given the immediate context, but this is actually a symptom (or "smell") that something is wrong with the wider design of the system. This article seems more about detecting choices around data struct…

That was my take as well. It's like seeing code with the same constant inlined in multiple places rather than centralized:

    // Use some inlined string as a magic code value:
    doStuff("Some Magic Code");
    
    ...
    
    // Later on same inlined string:
    doOtherStuff("Some Magic Code");
versus:

    // Define it once:
    const GOOD_NAME_FOR_MAGIC_CODE = "Some Magic Code";
    
    // Use it:
    doStuff(GOOD_NAME_FOR_MAGIC_CODE);
    
    ...
    
    // Use it somewhere else:
    doOtherStuff(GOOD_NAME_FOR_MAGIC_CODE);
   
If that triggers an "ah-ha!" moment for you then you've likely got bigger problems.

Re: Code Smells: Iteration

#9
post #2

At the risk of sounding arrogant, isn't this a bit obvious? To me, code smells are more about spotting when someone's been forced to do something a bit weird and convoluted. It's possibly the cleanest solution available given the immediate context, but this is actually a symptom (or "smell") that something is wrong with the wider design of the system. This article seems more about detecting choices around data struct…

It is obvious, but the code examples in the original link scare me.

Re: Code Smells: Iteration

#10
post #4
post #2

At the risk of sounding arrogant, isn't this a bit obvious? To me, code smells are more about spotting when someone's been forced to do something a bit weird and convoluted. It's possibly the cleanest solution available given the immediate context, but this is actually a symptom (or "smell") that something is wrong with the wider design of the system. This article seems more about detecting choices around data struct…

It's obvious to some of us, but not all of us. I see things way worse than this on a fairly regular basis.

I guess - but I feel like you'd call it an "error" rather than a "smell". Better to just teach people data structures rather than which constructs they should be afraid of. Approaching it "sideways" like this just leads to people going "I heard that loops can be bad, so I copied and pasted that line 25 times instead".
Post reply on HN