News for hackers. Stuff that matters.
Re:Go makes it easier to write correct, clear and efficient ... by kenhwang on Friday May 10, 2019 @04:22AM (#19876053)
I think complexity in software becomes difficult to grok as software gets bigger, and go does seem to go out of their way to code easier to understand at a hilariously micro scale at a huge cost at the macro level.
Re:Go makes it easier to write correct, clear and efficient ... by sagichmal on Friday May 10, 2019 @04:46AM (#19876148)
Absolutely the opposite. The ability to understand Go code seems roughly constant with regards to codebase size.

On teams of enough engineers, especially as those engineers rotate in and out of maintenance roles, richer abstractions tend to obfuscate intent and hurt maintainability more than help it.

Re:Go makes it easier to write correct, clear and efficient ... by asdkhadsj on Friday May 10, 2019 @08:27AM (#19877048)
Having been a professional Go programmer for ~5 years prior, now working in Rust full time, I actually take issue with Go for large code bases[1].

For me it's mainly due to the lack of generics and helper tools that naturally spawn from generics. Go's solution to having less LOC inside a function is _only_ to create helper methods/funcs. These helpers are bound to specific data structures and often are only applicable to that one use case in that one method that they came from. Your ability to make that helper function apply to more code depends heavily on what data structures are being used.

This form of non-generic bloat was far worse for me than the classic examples of `Fooi32()` and `FooString()`. The latter I don't mind at all.

Rust aids this process to me by, well, having generics. Converting one data structure into another becomes a breeze, and converting a Slice of those data structures is just as easy. I'll be really interested to see how Go feels once generics make it in - though I suspect I'll stick with more explicit memory management.

Speaking of memory management, it would be nice if Go had a way to intelligently indicate which structures are safe for concurrent use and which aren't. I've found in Rust that the explicit nature of the concurrent safety is not something I knew I wanted in Go. I know Go will not likely ever match Rust's safety, but if it at least indicated that something was an thread-unsafe implementation that would be golden.

[1] edit: Oh, and there is a disclaimer in this that the projects I'm involved in seem to heavily rely on managing several data structures in repeated ways. Aka, very generic friendly.. so not having generics made my projects extra painful. This is not likely the norm.

Re:Go makes it easier to write correct, clear and efficient ... by apta on Friday May 10, 2019 @10:32AM (#19878085)
> actually take issue with Go for large code bases

This has been my experience as well. People just parrot what the golang authors say about it being a language suites for "large scale development", whatever that means, without providing anything to back it up. Just because they said it was must be it's true? In practical experience, it's a verbose, clunky, and awkward language to use for any non-trivial code bases.

Re:Go makes it easier to write correct, clear and efficient ... by marcosdumay on Friday May 10, 2019 @10:37AM (#19878140)
Your disclaimer isn't really needed. Good generics support leads to good standard libraries, and using standard libraries is the norm.

Rust is still too young to take advantage of this, but in due time it will.

Re:Go makes it easier to write correct, clear and efficient ... by asdkhadsj on Friday May 10, 2019 @04:48PM (#19882085)
> Rust is still too young to take advantage of this, but in due time it will.

I actually find Rust's standard library great. I think my only complaint so far is the lack of time handling. Luckily community packages (like Chrono, Diesel, Tokio, Hyper, Itertools) have implemented great solutions to a few missing details.

Hell, Iterators alone make my life so much better.

Re:Go makes it easier to write correct, clear and efficient ... by snovv_crash on Friday May 10, 2019 @12:21PM (#19879266)
Go is designed to do concurrency via message passing, not shared memory. Yes, this is slower, but it also means you don't need a fancy borrow checker slowing down your compile.
Re:Go makes it easier to write correct, clear and efficient ... by nazka on Friday May 10, 2019 @12:58PM (#19879730)
Let me rephrase. Go was designed with the old best practice to share data of languages before Rust came: “you do not communicate by sharing memory, instead you share memory by communicating”. It is slower but you have to do this because Go can’t guaranty memory safety and doesn’t have system to prove that at compile time.

Then the team behind Rust after many research found that you can actually guaranty memory safety if you can track how data are used by each thread. To do this you need to track how each value is used and borrowed by each thread to insure memory safety. And so the borrow checker was born. It gives you the best of both world: speed And safety while adding only a little bit of time to the program to compile.

If Rust is slow to compile it’s not because of the borrow checker it only adds a little bit to the bottom line, but it’s because of Generics and other things. Which is also something that Go is lacking and doesn’t have yet.

Re:Go makes it easier to write correct, clear and efficient ... by perfmode on Friday May 10, 2019 @12:42PM (#19879528)
instead you pay for context switches in the scheduler and suffer an order of magnitude slowdown in production. and when you profile and find the performance issue, you rewrite the portion of code to use mutexed shared memory to hit your performance targets.
Re:Go makes it easier to write correct, clear and efficient ... by piano on Wednesday May 15, 2019 @09:56AM (#19919385)
> Go is designed to do concurrency via message passing, not shared memory.

... and yet experienced gophers will criticize newcomer's code for using channels too much and they will tell you you need to use traditional stupid shared memory approach instead of channels in many cases.

Re:Go makes it easier to write correct, clear and efficient ... by PeterisP on Friday May 10, 2019 @06:15AM (#19876482)
For complex, specialized systems what I'm often seeing is that essentially every decent large system gets split into a de-facto domain specific language (no matter if it's with language features or through some specialized libraries or webservices or whatever API) and the implementation of the business logic in that DSL. And, in general, the implementation of that DSL is something like ten times smaller than the amount of code using that DSL.

The maintainability of the code is mostly determined not by how good the underlying language is but how good is that DSL. To take an example that's been widely discussed in HN, let's think about machine learning - the look, structure and maintainability of your code is highly influenced by the choice of your framework/"DSL" e.g. pytorch vs tensorflow1.x vs straight numpy vs Caffe will have major differences despite being in the "same language".

And in that regard, the features of the core language matter only in regard of whether they facilitate making a good DSL. Of course, some languages fail because their choices result in the "core DSL" i.e. standard libraries that everybody uses being fragmented and confusing; Go has it quite good IMHO for the standard library; but for every specific domain it also matters if the DSL for that domain is good, whether it's an ORM layer or a OpenGL interface or a deep learning framework or an physics simulation library - whether the language abstractions mean that these DSL's (often being interfaces/wrappers to some third-party code written in another language) are going to be good and convenient, or whether the language structures limit the DSL so it becomes unwieldy to use.

Re:Go makes it easier to write correct, clear and efficient ... by sagichmal on Friday May 10, 2019 @07:17AM (#19876731)
> For complex, specialized systems what I'm often seeing is that essentially every decent large system gets split into a de-facto domain specific language

Every time I've seen this, it's been a disaster. Custom DSLs for business logic are, 100% of the time, a red flag of a development process gone off the rails.

(We may work in different industries.)

Go prevents you from doing this at a very low level. This is a huge advantage.

Re:Go makes it easier to write correct, clear and efficient ... by PeterisP on Friday May 10, 2019 @07:49AM (#19876863)
If you're writing a React or Django or Laravel or Rails app, then what you're doing is essentially work within that DSL which is quite different from the underlying Javascript/Python/PHP/Ruby language. The same goes for data analysis frameworks such as Pandas, or deep learning such as Tensorflow or Keras - if you're working in that most of your code and calls are going to be within that API/DSL, not "pure" Python. And I'd definitely consider all of the abovementioned as successes and a good thing - if Go would prevent people from writing their Web-CMS systems in a good Web-CMS framework/DSL, or writing their machine learning systems in a good ML framework/DSL, then that'd be a serious limitation.

And it's worth noting that many (all?) of these particular systems were actually initially made as custom DSLs for internal use within a single company - Rails for 37signals/Basecamp, Pandas for AQR Capital Management, Django for Lawrence Journal-World, Tensorflow by Google Brain, etc. They were the exact thing that you describe - a custom DSL invented for the business logic that the particular company needed repeatedly. And they were not a disaster but the right thing to do in their case - mostly because they had the ability to make a somewhat good DSL though in all those cases it was an 'okayish' DSL initially and became good only through years of substantial changes. Yes, for every such case there are many bad internal DSLs. "Not Invented Here" is a common problem. You need to ensure that you're using good DSLs, and good DSLs generally gain wide adoption within that domain instead of every company building their own shoddy DSL.

I've seen a bunch of nightmarish financial systems with horrible DSLs. However, even in that case the DSL problem was that this DSL was horrible not that a DSL shouldn't have been used - any fix or rewrite would generally require replacing it with a better DSL/framework/whole-encompassing-structural-API/whatever, instead of sticking to the core programming language (which would just result in another emergent "DSL" of some core libraries/classes, which would be lousy compared to something you intentionally design to be usable).

Re:Go makes it easier to write correct, clear and efficient ... by orbifold on Friday May 10, 2019 @11:51AM (#19878920)
I would say most of the examples you mentioned are actually examples of well implemented libraries, with well named methods and abstractions, rather than DSLs. If you want to imply that a good large codebase is similarly structured into libraries of independent components rather than one big class hierarchy then I would agree.
Re:Go makes it easier to write correct, clear and efficient ... by PeterisP on Friday May 10, 2019 @12:07PM (#19879109)
I'm probably trying to make a point that when writing code to a large domain-specific library or framework, at a certain level of intensity of coupling it de facto becomes a DSL. You're writing code using "primitive" data types, data structures and functions specific to that DSL instead of the data types of your core language; the control flow and data flow is not the same as in your core language but determined by that framework.

The differences between programming languages are smaller than the differences between DLS's implemented in the same language. Code in Rails (Ruby) and Django (Python) has more in common than code for Django and Pandas. Writing Tensorflow code in Python is somewhat similar to writing TensorflowJS code in Javascript, but very dissimilar to writing Pytorch code that does the same thing.

They're not really independent libraries, they're frameworks that suggest, influence and sometimes even mandate most of the infrastructure around your code and the structure of your code in a much more stringent manner than the core language does. There's a fundamental difference between making a few calls to a black box library versus having the content and style of most of your code being dominated by the traits of that "library" - the large frameworks overwhelm the small(ish) core languages. So I believe it's justifiable to consider the frameworks I mentioned as DSLs.

Re:Go makes it easier to write correct, clear and efficient ... by jimbokun on Friday May 10, 2019 @11:54AM (#19878954)
As PeterisP mentions, TensorFlow is an example of a massively, unequivocally successful DSL, which really wouldn't be possible with Go.
Re:Go makes it easier to write correct, clear and efficient ... by notacoward on Friday May 10, 2019 @09:43AM (#19877586)
Replace "DSL" with "idiom" and I totally agree with you. It's often possible to look at a code snippet and recognize what codebase it's from, even if it's doing something pretty generic. There are explicit local APIs, implicit local APIs (often associated with local data structures or stores), and local habits such as looping over items in a particular way. Managing memory, scheduling work, logging, and so on all tend to follow local rules. Those rules together are the moral equivalent of a DSL.

So you're right, for programming in the large it's very important how well the language supports creating good reusable APIs and data structures. I think that's why so many people make such a big deal about generics in Go, though personally I think it's a poor example and the complaints are tiresome. I think I'd focus more on whether the language has things like macros and lambdas/continuations that let non-API idioms be expressed consistently and conveniently, as though they're part of the language (even though I think creating a true DSL is usually a bad idea). Not sure Go meets this standard TBH.

Re:Go makes it easier to write correct, clear and efficient ... by jcadam on Friday May 10, 2019 @07:23AM (#19876757)
> ...the features of the core language matter only in regard of whether they facilitate making a good DSL.

Well, nothing I'm aware of beats the LISP family of languages as far as "making a good DSL" goes, but none of those are particularly popular :(

Re:Go makes it easier to write correct, clear and efficient ... by bsaul on Friday May 10, 2019 @07:56AM (#19876893)
except lisp aren’t statically typed, and so provide no refactoring capability or minimal safety at compile time.

But that’s another topic.

Re:Go makes it easier to write correct, clear and efficient ... by lispm on Friday May 10, 2019 @08:41AM (#19877155)
CLOS code:

   (defclass foo (superfoo1 superfoo2)
      ((some-slot :type bar)))

   (defmethod baz ((some-foo foo) (some-bar bar))
     ...)

   (defmethod foobar ((some-foo foo))
     (baz foo (make-bar)))
What would you need to do refactoring operations on such code? Given that there are classes, arguments are specialized over classes, slots have types, ...
Re:Go makes it easier to write correct, clear and efficient ... by marcosdumay on Friday May 10, 2019 @10:40AM (#19878180)
> What would you need to do refactoring operations on such code?

Some tool that can point where in a 1M lines of code project those classes are being used, and if they would need to change.

Re:Go makes it easier to write correct, clear and efficient ... by lispm on Friday May 10, 2019 @10:44AM (#19878222)
sure, go ahead. The type information is there.
Re:Go makes it easier to write correct, clear and efficient ... by bsaul on Friday May 10, 2019 @12:28PM (#19879335)
Didn't know about those type annotations in lisp, but i suppose what you mean is that an ide could parse all the code, infer the type of all the function / variables etc (just like the lisp interpreter would) and provide you with refactoring facilities ?

That's a good thing. But then comes the git merge (or any other automatic code altering tool). How do you know something hasn't been messed up in the process ? (unless you wrote unit test for every argument of every function)

Re:Go makes it easier to write correct, clear and efficient ... by lispm on Friday May 10, 2019 @12:50PM (#19879632)
> lisp interpreter

Lisp has compilers.

Some do also some type checking, here SBCL 1.5.2:

  (declaim (ftype (function (fixnum) fixnum) foo))
  (defun foo (a)
    (+ a 1))

  (declaim (ftype (function (fixnum) string) bar))
  (defun bar (a)
    (if (zerop a)
        "zero"
        "not-zero"))

  (defun baz (a)
    (foo (bar a)))
Then:

  * (compile-file "/tmp/test.lisp")
  ; in: DEFUN BAZ                                                                                                                                                                      
  ;     (FOO (BAR A))                                                                                                                                                                  
  ;                                                                                                                                                                                    
  ; note: deleting unreachable code                                                                                                                                                    
  ;                                                                                                                                                                                    
  ; caught WARNING:                                                                                                                                                                    
  ;   Derived type of (BAR A) is                                                                                                                                                       
  ;     (VALUES STRING &REST T),                                                                                                                                                       
  ;   conflicting with its asserted type                                                                                                                                               
  ;     FIXNUM.
Re:Go makes it easier to write correct, clear and efficient ... by marcosdumay on Friday May 10, 2019 @12:17PM (#19879214)
Indeed.

I had convinced myself I was reading Clisp, instead of CLOS.

Re:Go makes it easier to write correct, clear and efficient ... by lispm on Friday May 10, 2019 @12:40PM (#19879503)
CLOS is a part of Common Lisp. Fully integrated.
Re:Go makes it easier to write correct, clear and efficient ... by marcosdumay on Friday May 10, 2019 @12:42PM (#19879525)
Those type annotations are on clisp? I probably should get a project to test them :)
Re:Go makes it easier to write correct, clear and efficient ... by lispm on Friday May 10, 2019 @12:56PM (#19879700)
CLISP is an implementation of Common Lisp. The language is called Common Lisp.

Common Lisp has an object system with classes since the early 90s. In fact it was the first standardized object-oriented language.

Common Lisp also has optional type declarations. Not very sophisticated, but they are there.

Check out the SBCL implementation, which has a compiler which does some static type checking/inferencing.

http://www.sbcl.org

But one usually can use types/classes at runtime, too.

Re:Go makes it easier to write correct, clear and efficient ... by marcosdumay on Friday May 10, 2019 @02:17PM (#19880633)
Bookmarked for my next project. Thanks.
Re:Go makes it easier to write correct, clear and efficient ... by stouset on Friday May 10, 2019 @05:37AM (#19876335)
I just don’t buy it. We already work at a layer dozens if not more abstractions away from what’s really happening underneath the surface. This is essentially an argument that every layer below is good and justified, but that any additional layer is just too much.
Re:Go makes it easier to write correct, clear and efficient ... by coldtea on Friday May 10, 2019 @08:56AM (#19877252)
>Absolutely the opposite. The ability to understand Go code seems roughly constant with regards to codebase size.

That's what some Go proponents say, not necessarily reality, and there's no study about this, just hearsay.

I find Go hurts readability for larger programs because it prevents many structural abstractions that make code more clear and concise (as opposed to mere fancy "clever" code, which it still allows), and because it forces too much boilerplace (error handling, no generics, etc).

Every large projects contains re-implementations of the same things (from data structures to algorithms, to parallel processing handling) that could have been done once and re-used forever with generics and a little more power.

Re:Go makes it easier to write correct, clear and efficient ... by pjmlp on Friday May 10, 2019 @09:31AM (#19877490)
And then there is the copy-paste as means to avoid additional package dependencies.