Go makes it easier to write correct, clear and efficient code
yourbasic.org
yourbasic.org
So I clicked on this one. Started skimming through it, looking for code. Found none. Came back here to share my disappointment.
I'm always confused about articles that talk about code and have little code to show. Are there programmers who enjoy reading them? Or are these articles made for non-programmers?
Another thing that always throws me off is fluff. The article starts with "Choosing a programming language isn’t easy.". What does this add to the article? It immediately makes me think the author stuffed this article for no reason. So I have to skim even faster to not being cheated of my time. Is there anybody out there who thinks having the article prefixed with "Choosing a programming language isn’t easy." makes it more valuable?
Backward compatibility, compilation speed, circular dependencies, small vs big specs, etc. What code do you want to show about these aspects?
> The article starts with "Choosing a programming language isn’t easy.". What does this add to the article?
It's an introduction. It's a very common writing technique. You don't start with the core content of the article, you start with a paragraph or a sentence about why you wrote the article in the first place. You did the same with you "I love programming language" opening.
Backward compatibility, compilation speed,
circular dependencies, small vs big specs,
etc. What code do you want to show about
these aspects?
Code that shows these aspects. What broke in Java because of language changes and why. How handling circular dependencies in one language makes code uglier then in the other. Examples of the specs. You did the same with you "I love
programming language" opening.
That I love programming languages and to reason about them is an information about myself that the reader does not know in advance. That choosing a programming language is not easy is public knowledge that the readers already know. At least if they are programmers.That is the point of my post. Asking who the target audience is. And how it is different from myself.
Well that bit is certainly not true; passing by certain communities and you’ll be let known theres only one good answer: {lisp,c#,haskell,rust,js,c/++}
Please do not use code formatting for quotations.
Why not? I think it looks pretty good.If not code, how do you prove these assertions? How do you measure them?
> It's an introduction.
Inappropriate for an analytical argument. Common for infotainment (entertainment masquerading as information).
Read: It's a rant and/or PR.
- The article focuses on the properties of codebases, not individual code snippets. While it would be very valuable to do compare the properties of entire codebases, that is demanding on both the reader and the author.
- Opening the article with a statement like “Choosing a programming language is never easy...” is an acknowledgement of the fact that he is not claiming Go is unequivocally the best in all scenarios. The author is signaling that he is a reasonable person, and while that may seem like fluff it is a necessary component of communicating with a wide audience.
Probably there are languages that have a really expressive syntax that solve problems also in a scalable manner. For instance Python with its list comprehension that are a real code and time saver for software that does a lot with lists. (No coincidence it's so popular with ML.)
A list is much too slow because:
- Not contiguous - No SIMD vectorization - No parallel processing
Lists are mostly used for list of containers (for example storing the arrays inputs of a function)
All those arguments are fine and correct in small projects or libraries, there go is perfect.
But they really don't hold on big project like docker or containerd.
While it is clear what lines of code does, at a tactical level, it is extremely difficult to follow what happen in the big picture, the strategic level. Where the values comes from and where they go? When? How and why?
Honestly I keep seeing this in all big go project, despite the lack of generics.
Again if you need a small micorservice, use go! It is the best option right now. But I wouldn't bet any big codebase on it.
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.
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.
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.
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).
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.
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 :(
But that’s another topic.
(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, ...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.
I had convinced myself I was reading Clisp, instead of CLOS.
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.
But one usually can use types/classes at runtime, too.
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)
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.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.
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.
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.
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.
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.
... 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.
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.
Not maybe because of the lack of generics?
If I recall correctly one of the arguments for lack of generic was that they would make more obvious code, hence easier to follow and read. Actually it seems like the lack of generic just make more obvious code, hence more difficult to read.
The other argument was compilation speed, that honestly I cannot complain about.
I don't believe that is a reason ever articulated by the core team, but a post-hoc justification by apologists. The reason the core team gave was that they had not settled on a design that would fit well with their other goals for the language, and it simply didn't make the short list for 1.0.
Compared to python or Java? Well written python basically resembles Go. And most Java I've come across tries to spread logic across class boundaries so you never get to have all the code in front of you at one time.
I attribute it more to a static type system that lacks features I've grown use to in modern languages. Most of my experience in Java is 1.6 and prior so its possible code bases have improved since then.
You can build any abstraction you want in C.
This is disingenuous. Show me Pi types in C.
Interpreter, but close enough :)
Embedding a higher level language that's controlled from a more primitive host language allows solving many otherwise tricky problems without the struggle.
I took a quick look at what these are. Couldn't they implemented with macros like (this builds a type "Utf8String" which "depends" on the value of the "ENCODING" parameter to figure out what set of functions to call for the guts of the functions that handle the type, e.g. RawStringUtf8Length):
enum Encoding { Ascii, Utf8, Utf16 };
#define TYPENAME Utf8String
#define ENCODING Utf8
#define CHARTYPE char
#include "stringdef.ph"
Then in stringdef.ph (ph=parametric header, just came up with it): typedef struct { size_t len; CHARTYPE* text; } TYPENAME;
#define MAKEFUNC(name) TYPENAME##name
#define RAWSTRINGFUNC(name) RawString##ENCODING
void MAKEFUNC(Create)(TYPENAME* str);
void MAKEFUNC(Destroy)(TYPENAME* str);
void MAKEFUNC(CreateFrom)(TYPENAME* str, const CHARTYPE* text);
/* this goes in a single C file, single header library style */
#ifdef IMPLEMENTATION
void MAKEFUNC(Create)(TYPENAME* str) { ... }
void MAKEFUNC(Destroy)(TYPENAME* str) { ... }
void MAKEFUNC(CreateFrom)(TYPENAME* str, const CHARTYPE* text) {
str->len = RAWSTRINGFUNC(Length)(text);
str->text = RAWSTRINGFUNC(Duplicate)(text);
}
#endif
#undef MAKEFUNC
/* cleanup input parameters so includers wont need to do it */
#undef CHARTYPE
#undef ENCODING
#undef TYPENAME
Then you can use the above simply like Utf8String u8s;
Utf8StringCreateFrom(&u8s, "foo...");
It isn't exactly pretty, but seems to do the work. The ENCODING parameter is only conceptually an Encoding enum, but this can be enforced with some dummy (unused) code that does use of the ENCODING value as Encoding (and if extra strength is needed, as enums are weakly typed, instead of native enums, you could define macros that create stronger "enums" out of structs).Edit: And the intrusive data structures commonly used in C are way more complicated than the equivalent generic code (in my opinion).
- Download one that uses interface{} / void pointers - okay, but not very efficient or type-safe.
- Download one that's intrusive - okay, but pretty convoluted.
- Write my own - a pain.
- Code generation - generics but worse.
(This isn't sarcastic.)
The overhead of interface{} isn't as high as people sometimes think. You have the overhead of boxing the value, but the actual type checking is just a single comparison and jump.
This is way too much in a tight loop. I want my structure to fit in the cache and I want to have as little tests as possible.
But yes, if you're writing performance critical code (which you generally won't be), then you'll need to use code generation to avoid boxing.
This kind of discussion is pointless without some kind of real world reference point. The vast majority of Go projects will never run into a situation where the overhead of using interface{} is a performance bottleneck. If you're working on a project where you consistently have to think about the cache performance of your code, then C++ or Rust would probably be better choices. Go isn't meant to be all things to all people.
I have different kinds of constraints, mainly propositional clauses (a or b or c) and pseudo-boolean constraints (2a + b + c >= 2). Long story short, a propositional clause is a special kind of pseudo-boolean constraint, so I can process my clauses as if they were regular pseudo-boolean constraints, but this is slower than using dedicated code.
Lots of problems only deal with propositional clauses, so they take longer to solve than they should, because I cannot say "this is a problem with only propositional clauses", vs "this is a problem with all kinds of clauses". I could use interfaces, and tried, but this is way slower, to the point it doesn't make sense to use them.
And I can't use C++ or rust for this problem: there are already tons of very good c++ SAT solvers, but my goal was to provide a SAT solver I can use in my go programs without resorting to cgo black magic.
Yes, fair enough, I think that is a good example of the kind of code that Go is not particularly suited to (if performance is critical).
If that is a hard requirement, then the answer is just that Go isn't a suitable language. AIUI the current generics proposal in Go, it won't fix that problem for you either.
Where I disagree with the programming community at large is how often that's actually a hard requirement. A lot of programmers grossly overestimate their performance requirements on the microscale [1], and so concerns about "premature optimization" remain alive and well decades later. However, there are undeniably still a non-trivial number of cases where that really is a hard requirement, in which case the answer is, don't use Go.
(Preferably, figure that out before you start. As a fairly heavy Go user, I actually kinda cringe when reading one of the several "We sped up Go by 10x on our particular big thing and got to barely-acceptable performance" articles, rather than consider it something to be celebrated. I mean, cool that you sped it up that much and all, but honestly the correct answer was to notice in the design phase that you were doing something you probably shouldn't have done in Go, modulo concerns about easy prototyping and such.)
[1]: I qualify with "microscale" because I also think a lot of programmers underestimate the performance requirements on the macro scale. But that's actually a very different issue. There's a lot of very sluggish and slow code out there in the wild that is architecturally wrong; at every individual step the code is reasonably optimized and fast, the problem is having the wrong steps.
I honestly wonder if go isn’t cursed to follow the same road.
But yeah, I share your concern. It would be nice to have a better way to write container types in Go, but generics always seem to end up getting abused.
Blaming just generics for that does not work imho; in Java people were writing really insanely over complex code close after the first release; I had an ex C++ guy before 2000 writing Java code that used every design pattern in The Book, everywhere he could and it ended up with 1000s of files and those strange long names that became the standard for Java a few years later.
The cognitive overhead certainly is. Computers exist to help us do things faster and with fewer mistakes. This is a prime example of using a computer to help us make more mistakes, worse.
There is no doubt that not having generics makes some code worse than it would be with generics. But I think the problem is often overstated.
But if you are working on a project where the details of the tree do not matter (so you can use a library), you will probably use C++, not C. I still have a hard time understanding what niche Go fills, it's too high level to compete with C or Rust, but here we are comparing its expressiveness with C.
A red-black tree implemented in the same simple style by an OpenBSD developer a couple of decades later was adopted almost overnight by all BSDs: https://man.openbsd.org/tree#EXAMPLES
Unlike the Linux version, the BSD version is as type-safe as a C++ template, permits a node to exist in as many collections as you want (one member field per collection), and like a template the BSD version can inline the comparison function. You even have the option of making all the routines extern or static, which you can't even do with C++ templates.
What the Linux version has going for it is that it doesn't need to rely on the preprocessor so the implementation looks a little neater and more like a C++ template--no columns of backslashes as required with preprocessor-based generation. But that's a horrible tradeoff. queue.h and tree.h have basically been frozen for decades.[1] After initial curiosity wanes (day #2 of many thousands), nobody reads the headers because the interface is simple and never changes.
[1] Various systems have tweaked things here and there (e.g. to add parameterized trace points), but the original APIs never changed and code has always remained portable at the source level. The only big change over all that time was most systems (BSDs, macOS) eventually dropped CIRCLEQ after someone (I think a FreeBSD developer) posted benchmarks showing it sucked relative to TAILQ. I actually preferred CIRCLEQ; the entire header is small enough that for awhile I just copied it around everywhere.
Could you give a couple of examples how this is made clearer in other languages?
Someone with a detailed grasp of both can write clear code in C, Haskell, Python even BASIC
If you don't grasp either and have no time to be allowed to do it, no language will save you.
That is certainly true.
But the language can have a big impact on the difficulty of getting the implementation correct.
* dead-simple array/vector operations (http://www.mathcs.emory.edu/~cheung/Courses/561/Syllabus/6-F...)
* many useful built-ins (e.g., DOT_PRODUCT, MAXVAL/MAXLOC, MATMUL, TRANSPOSE)
* standard math libraries (e.g., LAPACK) with lots of very fast functions for linear algebra
mat a, b, x, tmp, c;
// ...
mat_mul(&tmp, &a, &x);
mat_sum(&c, &tmp, &b);
which is what OP meant if I'm not mistaken.Inside the Python code, each light has a Colour, and I built the Colour class with support for various math operators.
Want to make a Colour that's half as bright as another? Colour = OtherColour * 0.5. Want to blend two Colours? BlendedColour = OneColour + AnotherColour.
Doing this made all of the stuff that the code was doing incredibly obvious and straight forward. The alternative would have involved non-obvious helper functions and object methods or doing math directly on the rgb components encapsulated by each Colour object.
This was, for me, somewhat of a "light bulb" moment for operator overloading.
OneColor + AnotherColor does not have any obvious meaning. If colors are RGBA vectors, it could be vector addition. But is that what your blend operation does?
What's wrong with:
BlendedColor = blend(OneColor, AnotherColor)The meaning makes sense to me which, for a one developer codebase, is OK, but it's not something I'd want to do in a codebase supported by a larger team. I expect that in a more complete product that even the term "blend" would have multiple meanings.
Nothing wrong with writing:
Matrix_Multiply(m1,m2);
vs.
m1*m2
The first is not harder to read and not harder to write but I know exactly what's going on.
func main() {
a := big.NewInt(0)
b := big.NewInt(1)
var limit big.Int
limit.Exp(big.NewInt(10), big.NewInt(99), nil)
for a.Cmp(&limit) < 0 {
a.Add(a, b)
a, b = b, a
}
fmt.Println(a)
}
I can't say I'm particularly keen on having to read a.Cmp(&limit) < 0
instead of a < limit
The question is whether it's worth it to write code like this in order to prevent others from misusing operator overloading. I guess it may depend on how much math code you write and how disciplined your coworkers are.For your example, maybe so. But:
m = a * b * c + d * e + f
will be clearer than three Matrix_Multiply and two Matrix_Add calls. And one screen full of lines like mine will be far clearer than five screens full of Matrix_Add and Matrix_Multiply calls. invoice++
is not better than invoice.addToSystem()Also specifically for vectors and matrices for 3D graphics, i prefer to use float mtx[16], vec[3], etc instead of specifying custom types (then i can use the vec_foo calls with matrices with the proper offsets or the normal part of a float plane[4] which is encoded as normal+distance or use the vec_foo calls directly in a vertex buffer, etc).
I have really tried to like Go, but the imperativeness is just something I struggled with. Even good Go code is littered with breaks, mid-function returns and imperative loops. For those who want cross-platform native code but find Rust too complicated, hopefully C# will fill the void once CoreRT ships.
Otherwise, a language is more than its feature set. A big part of what makes a language enjoyable is its culture as well. I think C# is a great language, but I prefer Go's culture much more.
To me, Go culture is very arrogant, so much in fact that it almost reminds me of some Lispers of old.
Unfortunately similar thing can be said about Rust. However, in Rust, most of the crap seems to be comming from zealous newcommers and a loud minority, while the leadership and people involved seem relatively humble (or at least not too arrogant). In Go, OTOH, the arrogance seems to be stemming all the way from the top, judging from some talks & blogs by Pike, Cheney et al. Pike in particular seems to me to be a very arrogant, unpleasant person. I respect him very much as an engineer, but I will never like the way he speaks, promotes Go and spreads FUD about other languages.
Java has AOT compilers available since around 2000, just not for free.
And there are plenty of other languages with AOT compilers to native code.
I tend not to care all that much about the language itself. What I care about is productivity and that I don't need to have a discussion about what language people would rather program in every 3-4 months. This is why I get suspicious when people say they are language enthusiasts. I leave it to the team to choose language, but it has to fit some minimum criteria and I don't want whining afterwards and I don't want a mishmash of languages "because it fit the domain better".
That's why I like Python over Go, C# and others. Python lets me fit more functionality (expressed as code) in my working memory, and I have to ignore less line noise and boilerplate.
ps: note that I'm not criticizing FP or static/math oriented programming. I'm just trying to pu both sides into a shared perspective
And that's what it comes down to, almost always. How hard is it to hire other people to work on your code, and how hard is it to bring people up to speed, who need to code, but aren't programmers. Scientists, mostly. Business people increasingly.
Jane Street, for example, went with OCaml in part because the business people found the code easier to review than other languages.
That said, the fact that OCaml is used by Bloomberg and Facebook (on multiple apps and products) alone make it not niche http://www.ocaml.org/learn/companies.html
That plus ReasonML's growing popularity, which is essentially just a syntax extension of OCaml, makes it even further not niche.
And that counts in all sorts of ways. You'll have much more trouble finding answers to any questions you have. You'll have less chances for community meetings or educational content. You'll definitely have more trouble finding new developers for your projects, both in business and in open source.
Erlang doesn't support mutation at all, for example, and uses immutable types for everything. But it does let you send messages to other processes, which is a side-effect, so Erlang is not purely functional. But that doesn't mean that JavaScript is somehow just as functional as Erlang. Because it's not.
Starting with Haskell is a bad idea, no doubt.
But there are easy to use functional languages that are very beginner friendly, like Elixir or Elm.
I not sure I agree. The university I went to used Haskell for its introduction to programming courses and I think it worked pretty well for most people, and especially for people who had never programmed before. The people that did struggled the most where actually those who already knew a bit of programming, but weren't very strong programmers.
The flip side is that all the students who had now had been introduced to programming via Haskell where completely confused when trying to understand OO and Java in the next course.
It's easier than teaching them imperative programming, because it's much easier to reason about.
The real problem is teaching functional programming to programmers whose brains have been damaged by years of writing imperative programs.
Preemptive strike against whitespace comment.
Especially C++ and C# are notorious for hiding what actually happens, and in a worse way. Their performance however is more predictable, which is important in some cases.
There's not a lot of difference between usage of such modules in Python "hiding" complexity and abstractions used in Java, C#, C++ or Rust except those languages don't actually need to use FFI to get acceptable speed. Computer Science is pretty much just layers and layers of abstractions and the level of abstraction that Go or Python chose to operate on isn't special in any way.
I only meant to say that in my opinion something like C++ "hiding" behavior in libraries, classes or through operator overloading is not different from Python where easy to use modules hide extreme amounts of complexity. In fact, C++ is better, because it uses FFI way less than Python and by being a lower level language it limits the maximum possible difference in abstraction level between visible and "hidden" code.
My industry (defense and govt contracting) is still big into Java, but we traditionally run at least 10 years behind the state of the art. At some point (maybe in another 10 years) I expect to see the cube farms full of Java code monkeys replaced by cube farms full of Golang code monkeys. Big body shops (which is what the majority of my industry is) love mediocrity and overstaffed programs.
By that time the cool kids will have moved on to something else. Maybe they'll rediscover OOP or some such.
Is there some language that's used by cool programmers that allows them to write complex code(equivalent of millions of lines of code written by "code monkeys" -- or 10 lines of code written by the gods) ?
Is there a conspiracy against said language that these god programmers write that prevents it from taking over the world (besides the "code monkeys" not being able to learn it?
Because in my experience once you get to decently complex projects, the (modern)language doesn't really matter that much.
My intuition is the above is applicable even for small projects, and that beyond hand picked examples, the programming language doesn't really matter as long as you're comparing apples to apples -- that is some business functionality, the choice is based just on the ecosystem.
WhatsApp famously built a company with a billion users, sold for $19 billion, with about 50 engineers, with a product built in Erlang. I think that's the best example of what you're asking about. It's not clear they could have accomplished the same success with any other language.
However, to argue that its easier to write "good" code, is hyperbole of the highest order.
A programming language is a brush with which to paint your logic. If your picture is murky its because you, the programmer has made it murky.
There are many tradeoffs with "good" code. Readability, speed, compactness, modularisation, use of libraries. As with any other practical subject, your skill comes from practice. Yes, new tools can make it _easier_ to be more efficient, or faster. They might even badger you into good habits.
But
They cannot make you "good". Its the expensive camera fallacy. Sure a Medium format SLR will take _spectacular_ pictures, but only if you use it properly. A good photographer will be able to take wonderful images using a camera phone from 2006.
Which underscores my point. When you are building a table in real life you make it all from one or two materials. You'd keep to one or two types of fasteners, because its simple quicker an easier.
You don't change halfway through from turned oak to carbon fibre, "because its higher performance." unless you have a bloody good reason to change.
Sure I've used screws as nails, it works pretty well, but we all know its a dirty hack.
The Python code snippet del a[i] deletes the element at index i from a list a. This code certainly is quite readable, but not so transparent: it’s easy to miss that the time complexity is O(n), where n is the number of elements in the list.
Go doesn’t have a similar utility function. This is definitely less convenient, but also more transparent. Your code needs to explicitly state if it copies a section of the list. See 2 ways to delete an element from a slice for a Go code example.
I think this assertion is wrong. del in python does exactly what it says it does. There are precisely three reasons to not use del: o Because you have written your program, got all the low hanging performance fruits, and now need to optimise how you delete from (large) lists, and dequeue doesn't work for you
o you are arrogant and want to show everyone how clever you are because you understand how list operation are handled under the hood. So you have written your own.
o a.remove()/a.pop() you think is more readable.
It is far more important to be readable than to be fast in 90% of cases. If we all really cared about speed, then React/electron/et al would never be a thing.I really appreciate taking a minimalist and opinionated approach to language design but all design choices done in Go comes at a cost and the above broad statement simply is not correct. And to me it just adds to the impression of the Go community of being on the immature and almost cultish side.
> Java inner classes suddenly appeared in 1997; it took more than a year to update the specification, and it became almost twice as big as a result. That’s a high price to pay for a non-essential feature.
I can't talk about the doubling of the specification but you can learn everything you need to about inner classes on 5 pages or so. It's over 20 years old now.
> generic arrays aren’t supported
So you can't use something with arrays that go doesn't even support ;-)
> type wildcards with upper and lower bounds are quite complicated.
Well, it's two words (extends and super) and some syntax. How could it be much easier?
> Enum [...] It’s certainly nice to have, but offers little that couldn’t be done with ordinary classes
Yes, and generics offer little that couldn't be done by implementing specialised classes. Enums are there to help you. You see an enum? You know what happens, you know what it offers, you know it's not a "normal" class but is there for a special reason.
Yes, Java does have its inconsistencies. Why is String Immutable when in a OO-language the opposite would be taken for granted? Why can't you use int as a datatype for an ArrayList but Integer? What's up with Stack and Deque and Vector? You have to know Java to work with it effectively. We are professionals after all. It can be expected that we know the language. Java gets the job done.
That's not to say that Go couldn't get ahead of Java and may be the better language (especially in the future). But the ecosystem is far from it for now and Go has to prove it won't suffer from the same problems Java is now.
Folks new and old to Go still write data-race riddled code unless they put in the extreme mental effort and care into avoiding data-races. Also, if they write good unit tests that help them spin through the code they can often double-down on ensuring their code is correct by using the race-detector.
Even if you do all of this...sorry but there’s no guarantees.
In my opinion this is why we are seeing languages like Rust invest heavily in something like the borrow checker...to prove at compile time when you have racy code.
If Go had a compile time ability to do this it would be really amazing.
Yes, this all my experience and opinion.
Check out Pony.
I’d be happy to offload such mental hoops to the compiler.
This article is no exception.
I'm not partial to Go, Java or Python, but I do wish this sort of article stopped making headlines, leaving room for finer analyses and experience reports. These are what we really need.
For instance, you have to add literally one line of code to terminate Java application at the end of main function. Why would such a minute feature of language make Java programs harder to reason about? Why would anyone even present this argument as a serious one?
> The Python code snippet del a[i] deletes the element at index i from a list a. This code certainly is quite readable, but not so transparent: it’s easy to miss that the time complexity is O(n), where n is the number of elements in the list. Go doesn’t have a similar utility function. This is definitely less convenient, but also more transparent. Your code needs to explicitly state if it copies a section of the list. See 2 ways to delete an element from a slice[0] for a Go code example.
But the examples given in [0] could also be implemented in Python as well with, I dare say, the same time complexity.
I actually really like the error handling in Go and think it makes it easer to write good code. At least for simple programs.
This is one glaring exception: Concretely typed objects can be silently converted to interface objects. In particular, a `*MyErrorStruct` can be silently converted to an `error`. The giant footgun associated with this conversion is that because the resulting interface object "remembers" its concrete type, it won't compare equal to `nil`, even if the original value was in fact `nil`.
This is a pretty big exception, which I've seen cause bugs in production. It's common to have one function that returns a concrete type wrapped by another function that returns an interface. That means the silent type conversion is happening in the `return` statement, which is extremely easy to overlook. (Or which can be introduced after the fact by changing the signature of either function.)
Its still a better C in many ways, strings and character sets is a big one.
I love ruby I would like to work with Ruby 100% of the time but yeah... too many downsides.
I use it, but feel its design insults my intelligence.
Sure Oracle may not be the wonderchild, but at least they don't store everything they can about me without me having any say in the matter.
Gmail, Search and Go (yes it's my fav language so far) runs or helps my business greatly and with a direct impact on my income so yes...I'll gladly share my fetishes with the big brother. I don;t want to but I have no better alternatives. Do you?
I think your frustration comes from the fact that you want to avoid using their products but can't find better alternatives. Also, no need to call people names and...use your own username; don't go green in fear of internet points.
> Why bother protesting you imperfect hypocrite?
As a thing that people are saying to the hypothetical Greenpeace protester, not a thing that GP is directing at you.
No. No. Yes. Yes. No.
But all departments is still controlled by the company itself. No matter how good hearted the Go devs are, they are still paid by Google and I don't want to contribute to their power any more than I have to.