News for hackers. Stuff that matters.
Re:Practical Go: Real-world advice for writing maintainable ... by networkimprov on Thursday February 21, 2019 @03:17PM (#19220207)
Go has closure functions; great feature.

One of the (few) things I like about Javascript is the ability to define a closure anywhere in the containing function, so it appears in the order of operations:

  function f() {
    setTimeout(fDing, 2000);
    g();
    function fDing() {
      ...
    }
  }
Re:Practical Go: Real-world advice for writing maintainable ... by johndubchak on Thursday February 21, 2019 @03:43PM (#19220408)
Disclaimer: I have no Golang programming experience.

I am curious with this approach though...you're nesting behavior and/or logic, doesn't this further obscure the meaning of the code and contribute more to the need to jump around the source in order to figure it out?

Re:Practical Go: Real-world advice for writing maintainable ... by vram22 on Thursday February 21, 2019 @05:56PM (#19221401)
Go has anonymous functions too.

The Go Programming Language book (Kernighan and Donovan) has some examples of them.

Re:Practical Go: Real-world advice for writing maintainable ... by SaltyBackendGuy on Thursday February 21, 2019 @05:39PM (#19221227)
Now write a unit test for

    function fDing() {
      ...
    }
Honestly with modern JS I am not sure this feature is that great. Looks more like a code smell these days imo.

Edit: Formatting

Re:Practical Go: Real-world advice for writing maintainable ... by Roboprog on Thursday February 21, 2019 @06:12PM (#19221543)
Now write a unit test for the inline block of code within the longer function which would have become the nested function???

You write the test (where any is needed) for the outer function.

Edit: the start of the discussion was about using nested functions to decompose what otherwise would have been “unpartitioned” long functions. Such blocks of code nested within a long function would not be possible to unit test, either.

Unit tests, rather than integration tests, are usually bogus, anyway, though.

Re:Practical Go: Real-world advice for writing maintainable ... by int_19h on Thursday February 21, 2019 @11:01PM (#19223018)
You write unit tests for units of code. A function with nested functions inside of it is a single unit of code; that's essentially what those functions being nested, and hence not directly invokable from the outside, indicates.
Re:Practical Go: Real-world advice for writing maintainable ... by kazagistar on Friday February 22, 2019 @10:52AM (#19226309)
Make private functions that are only visible to the current module. Then write your unit tests directly in that same module, next to the functions, so they can access them even when the rest of the world cannot. Of course, this requires sensible language support.
Re:Practical Go: Real-world advice for writing maintainable ... by Roboprog on Friday February 22, 2019 @09:39PM (#19231247)
Hierarchy vs list. I don’t want a list (of subroutines). I want a tree of self contained routines. Only your containing routine uses you. Which “private“ routines use which? (I know the IDE will tell me about this routine, and that routine, but I don’t want to have to ask)

Your employer doesn’t want you testing getters, anyway, but rather features. Unit test fanatics need to stop.

I guess unit tests were useful for C++, when it was constantly crashing everything :-(

C++ and its legacy need to ride off into the sunset, already.