News for hackers. Stuff that matters.
Re:Go + Services = One Goliath Project by baddox on Saturday December 21, 2019 @08:12PM (#21854444)
But python for loops can and typical do have multiple lines, yet that “block” inside the for loop doesn’t have a name. The fact that the body of a for loop can have multiple lines but an anonymous function cannot is a purely arbitrary syntax limitation, and the principle you stated ought to apply (or not apply) equally to both use cases.
Re:Go + Services = One Goliath Project by joshuamorton on Saturday December 21, 2019 @08:30PM (#21854523)
This doesn't follow: for loops are there specifically for cases of the complexity that can't be handled by other constructs (like comprehensions). Anonymous functions are not, for the complex cases you give the construct a name.

It's a very intentional language limitation, much as semantic whitespace is an intentional limitation.

And there is actually a language difference. A for loop is a statement. A lambda is an expression. Python doesn't let you put statements into expressions.

Re:Go + Services = One Goliath Project by lesserknowndan on Saturday December 21, 2019 @09:09PM (#21854678)
I tentatively disagree with both of you.

I've sometimes wondered whether code would be universally clearer if all you could do in a loop is have a one-liner or call another function/method (mainly when looking at my own code within loops and thinking WTF!!!).

Would probably cause issues when teaching programming though. It would be interesting to have a compiler switch that enforced this...

Re:Go + Services = One Goliath Project by baddox on Saturday December 21, 2019 @11:05PM (#21855111)
What comes to mind immediately is that you would lose the ability to `break` unless you had another convention like returning a specific value to indicate you want to break.
Re:Go + Services = One Goliath Project by lesserknowndan on Sunday December 22, 2019 @04:16AM (#21856098)
If you are limited to one statement you could still do something along the lines of the following (no particular language):

  foreach ( $item in $list )
  {
    if ( 1 == some_function( $item ) )
    {
      continue;
    }
    else
    if ( 2 == some_function( $item ) )
    {
      break;
    }
    else
    {
      another_function( $item );
    }
  }
But I would immediately concede that it is starting to miss the entire point of why it was enforced in the first place...
Re:Go + Services = One Goliath Project by joshuamorton on Saturday December 21, 2019 @11:36PM (#21855205)
I actually like this style (or similar if not quite as extreme). I find it's much clearer what's going on.
Re:Go + Services = One Goliath Project by dwaltrip on Saturday December 21, 2019 @08:19PM (#21854468)
Thanks for writing this, that clarifies the issue more clearly and concisely than what I had in mind.

I will mention a core aspect of my argument, to add to your point.

When you make a named function and then use it separately somewhere else, there is a loss of locality. The logic is now further from its point of use. This is a cost, and sometimes it is an unreasonable one.

Re:Go + Services = One Goliath Project by guitarbill on Saturday December 21, 2019 @08:44PM (#21854578)
i'd agree with this, except you can have a function within a function in Python to limit scope and keep it local. yeah, you have to define it before the code using it - sometimes this feels like a boon though, especially compared to huge inline lambdas. so over time, my annoyance with this has decreased, and it doesn't bother me anymore.