News for hackers. Stuff that matters.
Re:Code Smells: Iteration by masklinn on Wednesday August 23, 2017 @11:49AM (#15082471)
> If you see collection.map(...) you know that each iteration is simply a pure function from original element to transformed element, which is an immense help when reading the code.

You'd think so, but I've had colleagues who managed to fuck that up and use map or list comprehension solely for side-effects.

Re:Code Smells: Iteration by apta on Friday August 25, 2017 @08:02AM (#15097779)
I saw some code like this:

    def update(): Try[Unit] = {
      parser.parse(...).map(result => updateState(result))
    }
And I thought it was abusing the map() call for side effects. However, it is still shorter than writing it out as follows:

    def update(): Try[Unit] = {
      parser.parse(...) match {
        case Success(result) =>
          updateState(result)
          Success(())
        case f@Failure(_) =>
          f
      }
   }
So I didn't have a strong opinion either way since semantically both do the same (and in the case of Scala, the first one is potentially more performant since it relies on the JVM doing virtual dispatch as opposed to calling unapply() and matching, not to mention potentially less garbage being generated).
Re:Code Smells: Iteration by OtterCoder on Wednesday August 23, 2017 @05:47PM (#15085520)
Even Excalibur can be used to mince garlic, and even a supercomputer can be used to play Zork.
Re:Code Smells: Iteration by masklinn on Thursday August 24, 2017 @08:38AM (#15089565)
Yeah I mean my point is "trust but verify", I love restricted iteration construct, but just because they're being used does not mean they're being used "properly" unless the language ensures it.
Re:Code Smells: Iteration by mikojan on Wednesday August 23, 2017 @04:25PM (#15084740)
This. I've seen FP features (and incidentally OOP features as well) misused so hard, I'm thankful for every plain loop (or struct for that matter).