News for hackers. Stuff that matters.
Re:John Carmack on Inlined Code by MichaelGG on Friday September 26, 2014 @05:10PM (#8374878)
This is why I prefer a language where everything is an expression, and I can nest things without limit. If I need a simple, but narrow-use helper function? Why, define it inside the function I need it in, and use it a handful of times (or once).
Re:John Carmack on Inlined Code by ufo on Friday September 26, 2014 @06:07PM (#8375164)
Doesnt need to be an expression language for that. Algol and Pascal had nested procedures and lexical scope but still had traditionla imperative statements.
Re:John Carmack on Inlined Code by MichaelGG on Saturday September 27, 2014 @03:16AM (#8376346)
I meant I want both features. I want to be able to write "let x = if a then y else z", and I also want to nest things.

But if everything is an expression, then nesting seems to arise naturally.

Re:John Carmack on Inlined Code by seanp2k2 on Friday September 26, 2014 @05:51PM (#8375105)
Could you please explain why it'd be useful to do that for something you'd only use once, esp only within that function? I honestly don't see how that's useful or more clear. Some examples with explanations would probably help. Thanks :)

(Edited to fix minor typo)

Re:John Carmack on Inlined Code by MichaelGG on Saturday September 27, 2014 @03:26AM (#8376356)
So I opened up one of my files and found the first instance of this. It was a function to load some subset of data and emit some log info. It was only called once, at the end of a chain of maps and filters.

  let load_x xid = 
    // loading code

  // Later on...
  let data' = foo |> map ... |> filter ... |> ... |> map load_x
Once you view functions as values like anything else, then making single-use, "temporary" functions seems as normal as temporary or intermediate variables.
Re:John Carmack on Inlined Code by Tloewald on Friday September 26, 2014 @07:12PM (#8375378)
Just consider naming clarity. It's just like using i for an iterator variable -- if it were global or file-wide in scope it would be disastrous, but because it's local to the block it's simple and intuitive.

Similarly you can give a little helper function a short, obvious name knowing it won't have side-effects.