Live data from Hacker News

Go is my hammer, and everything is a nail

maragu.dev

791–800 of 816 posts

Re: Go is my hammer, and everything is a nail

#791
post #749

Earlier quoted context omitted.

> The person you are responding to didn't say that, I did. Ah, thanks, I got confused. > Haskell works really well if the problems you're solving don't have a ton of weird edge cases, but often reality doesn't work like that. In my experience it's completely the opposite, actually. I can only really write code that correctly handles a ton of weird edge cases in Haskell. It seems that many people think that Haskell is…

> Granted, that is noisier than the Python, despite being a direct translation. My complaint isn't the noise. My complaint is: can you explain what withJump does? Like, not the intention of it, but what it actually does? This is a rhetorical question--I know what it does--but if you work through the exercise of explaining it as if to a beginner, I think you'll quickly see that this is isn't trivial. > 1. You don't ge…

Thanks for your detailed reply! As a reminder, my whole purpose in this thread is to try to understand your comment that Haskell is

> impractical to be used as a general-purpose language (because I don't think it's intended as a general-purpose language)

From my point of view Haskell is a general purpose language, and an excellent one (and in fact, the best one!). I'm not actually sure whether you're saying that

1. Haskell is a general purpose language, but it's impractical

2. Haskell is a general purpose language, but it's too impractical to be used as one (for some (large?) subset of programmers)

2. Haskell is not a general purpose language because it's too impractical

(I agree with 1, with the caveat I don't think it's significantly less practical than other general purpose languages, including Python. It's just impractical in different ways!)

That out of the way, I'll address your points.

> can you explain what withJump does? Like, not the intention of it, but what it actually does? This is a rhetorical question--I know what it does--but if you work through the exercise of explaining it as if to a beginner, I think you'll quickly see that this is isn't trivial.

Yes, I can explain what it does! `jumpTo break` throws an exception which returns execution to `withJump`, and the program continues from there. Do you think explaining this to a beginner is more difficult than explaining that `break` exits the loop and the program continues from there?

> It's certainly unintuitive, but I can't think of a case this has ever caused a problem for me in real code.

I can! And not just me. It's caused a lot of problems for a lot of users over the years: https://stackoverflow.com/questions/54288926/python-loops-an...

> Again, is this actually a problem? Any high school kid learning Python can figure out how to set a flag to exit a loop. It's not elegant or pretty, but does it actually cause any complexity? Is it actually hard to understand?

Yes, I would say that setting flags to exit loops causes additional complexity and difficulty in understanding.

> And lots of languages now have labeled breaks.

I'm finding this hard to reconcile with your comment above. Why do they have labelled breaks if it's good enough to set flags to exit loops?

> Arguably the Lua solution (gotos) is the cleaner solution here, but that's not popular. :)

Sure, if you like, but remember that my purpose is not to argue that Haskell is the best general purpose language (even though I think it is) only that it is a general purpose language. It has at least the general purpose features of other general purpose languages. That seems good enough for me.

> What does this even mean? In concrete terms, why do you think I can't see what effects are possible in Python, and what problems does that cause?

    def foo(x):
        bar(x + 1)
Does foo print anything to the terminal, wipe the database or launch the missiles? I don't know. I can't see what possible effects bar has.

    foo1 :: e :> es => IOE e -> Int -> Eff es ()
    foo1 ioe x = do
        bar1 ioe x

    foo2 :: e :> es => IOE e -> Int -> Eff es ()
    foo2 ioe x = do
        bar2 (x + 1)
I know that foo2 does not print anything to the terminal, wipe the database or launch the missiles! It doesn't give bar access to any effect handles, so it can't. foo1 might though! It does pass an I/O effect handle to bar1, so in principle it might do anything!

But again, although I think this makes Haskell a better language, that's just my personal opinion. I don't expect anyone else to agree, necessarily. But if someone else says Haskell is not general purpose I would like them to explain how it can not be, even though it has all these useful features.

> In all three of the cases that you mention, I can see a sort of aesthetic beauty to the Haskell solution, which I appreciate. But my clients don't look at my code, they look at the results of running my code.

Me too, and the results they see are better than if I wrote code in another language, because Haskell is the language that allows me to most clearly see what results will be produced by my code.

> The fact that you need a blog post to tell people how to resolve an issue exemplifies my point that this is not resolved. Nobody needs to be told how to turn off laziness in Python, because it's not turned on.

Hmm, do you use that line of reasoning for everything? For example, if there were a blogpost about namedtuple in Python[1] would you say "the fact that you need a blog post to tell people how to use namedtuple exemplifies that it is not a solved problem"? I really can't understand why explaining how to do something exemplifies that that thing is not solved. To my mind it's the exact opposite!

Indeed in Python laziness is not turned on, so instead if you want to be lazy you need blog posts to tell people how to turn it on! For example [2].

> The fact is, Haskell does the wrong thing by default here

I agree. My personal take is that data should be by default strict and functions should be by default lazy. I think that would have the best ergonomic properties. But there is no such language. Does that mean that every language is not general purpose?

> even if you write your code to evaluate eagerly, you're going to end up interfacing with libraries where someone didn't do that.

Ah, but that's the beauty of the solution. It doesn't matter whether others wrote "lazy code". If you define your data types correctly then your data types are free of space leaks. It doesn't matter what anyone else writes. Of course, other libraries may use laziness internally in a bad way. I've fixed my fair share of such issues, such as [3]. But other libraries can always be written in a bad way. In Python a badly written library may cause an exception and bring down your worker thread when you weren't expecting it, for example. That's a weakness of Python, but it doesn't mean it's not a general purpose language!

> Laziness still gets advertised up front as being one of the awesome things about Haskell

Hmm, maybe. "Pure and functional" is the main thing that people emphasizes as awesome. You yourself earlier brought up SPJ saying that the next Haskell will be strict, so we both know that Haskellers know that laziness is a double edged sword. I'm trying to point out that even though one edge of the sword of laziness points back at you it's not actually too hard to manage and having to manage it doesn't make Haskell not a general purpose language.

> and while experience Haskell developers are usually disillusioned with laziness, many Haskell developers well into the intermediate level still write lazy code because they were told early on that it's great, and haven't yet experienced enough pain with it to see the problems.

Hmm, maybe. I don't think people deliberately write lazy (or strict) code. They just write code. The code will typically happen to have a lot of laziness, because Haskell is lazy by default. I think that we agree that that laziness is not the best default, but we disagree about how difficult it is to work around that issue.

I would be interested to hear whether you have more specific ideas you can share about why Haskell is not a general purpose language, in light of my responses.

[1] https://blog.teclado.com/pythons-namedtuples/

[2] https://www.tothenew.com/blog/exploring-pythons-itertools-mo...

[3] https://github.com/mrkkrp/megaparsec/issues/486

Re: Go is my hammer, and everything is a nail

#792
post #94

People always under-estimate the cost of properly learning a language. At any given time I tend to have a "main go-to language". I typically spend 2-4 years getting to the point where I can say I "know" a language. Then I try to stick to it long enough for the investment to pay off. Usually 8-10 years. A surprising number of people think this is a very long time. It isn't. This is typically the time it takes to under…

One of the most important qualities of Go is that it is actually possible to fully understand the language -- in the sense that you never see a snippet of Go code and think "wtf, you can do that?" or "hang on, why does that work?" Getting to that point takes many years, to be sure. But the language is simple enough, and changes slowly enough, that it is not an unrealistic goal -- the way it would be in C++, or Rust,…

I've been doing Go for a long time now and I still occasionally come across snippets of code that I don't understand or understand the purpose of. So I think "never" is too strong a word. I'd say "rarely" rather than "never".

Re: Go is my hammer, and everything is a nail

#793
post #473
post #94

People always under-estimate the cost of properly learning a language. At any given time I tend to have a "main go-to language". I typically spend 2-4 years getting to the point where I can say I "know" a language. Then I try to stick to it long enough for the investment to pay off. Usually 8-10 years. A surprising number of people think this is a very long time. It isn't. This is typically the time it takes to under…

I believe people over-estimate the benefit of properly learning a language. 3-12 months seems to be sufficient for the specialisation benefits to outweigh the small hit to language competency. My strategy is to be a generalist superficially learning specialized languages.

The way to become good at something is to do it for a long time and to be willing to think about what you are doing and continually improve.

There's much more to learning a language properly than just learning the language spec itself. Especially if we're talking about languages such as Java, where you have to know quite a bit about how the runtime works in order to be able to make good design decisions. And Go isn't really that simple either when we start to get into the weeds of performant concurrent systems that also need to be robust. It requires quite a bit of work to be able to make full use of what Go offers. It may look simple, but concurrency never is.

You're essentially arguing in favor of not being good at what you do, or at best being mediocre at lots of things. And I'm sure there are lots of jobs where that is okay. The thing is: why would you want to spend a lifetime being mediocre, to work on mediocre projects with other people who are mediocre?

Re: Go is my hammer, and everything is a nail

#794

Earlier quoted context omitted.

Fwiw I have worked on multiple many hundred of thousands lines of code projects in multiple languages, several of which we rewrote from python, perl, php, and ruby to go where I first maintained the existing code and then worked on a rewrite. I've also walked into existing large Go projects and worked in elixir and some limited js. In each and every case except one (some contractors did something really odd in trying…

Meaningful comparisons between programming languages are difficult. I've done rewrites of Python programs in Python, and the rewrites were more performant and easier to maintain. My point is, is it the language? Or is it the fact that when you rewrite something, you understand which parts of the program are difficult, you know the gotchas, and you eliminate all the misfeatures you thought you needed the first time bu…

Hands down, the language made the projects easier to maintain. I have also rewritten from php to python, python to python, and perl to perl, many greenfield projects in each, etc.

Why did the language matter? Largely, static typing, concurrency ergonomics, fast compilation, and easy to ship/run single binaries. The fact it also saved 10-20x in server costs was a great bonus.

Better design can absolutely improve a project and make it easier to maintain and more performant. And bad code can be written in any language. I am more and more convinced that dynamically typed code doesn't have a place in medium to large organizations where a codebase no longer fits in one person's head.

Re: Go is my hammer, and everything is a nail

#795
post #94

People always under-estimate the cost of properly learning a language. At any given time I tend to have a "main go-to language". I typically spend 2-4 years getting to the point where I can say I "know" a language. Then I try to stick to it long enough for the investment to pay off. Usually 8-10 years. A surprising number of people think this is a very long time. It isn't. This is typically the time it takes to under…

ChatGPT accelerates this timeline significantly. As a senior programmer you can largely skip the "junior" phase of the learning, almost like pair programming with a very proficient junior programmer.

I disagree. ChatGPT is like pair programming with someone who is on drugs and tends to lie a lot. Co-Pilot is even worse as it constantly bombards you with poor suggestions and interrupts your flow when you should be left alone to think about the problem you are solving.

What separates a senior developer from a junior is that the language is no longer a barrier so your spend most of your time thinking about the problem you are solving and how you balance requirements, take into account human elements, and try to think ahead without prematurely spending time on things you aren't going to need.

Being shown a bunch of possible solutions to choose from doesn't help you develop the ability to think about problems and come up with better solutions.

Yes, ChatGPT can occasionally help you when you need a nudge to pick a direction or you come across something you don't know anything about. But it is not a substitute for knowing stuff and it can't actually teach you how to think.

Re: Go is my hammer, and everything is a nail

#796
post #719

Earlier quoted context omitted.

At the expense of absolutely massive, gargantuan, entire-OS-sized binaries. Just looking at my bin/ folder eg k9salpha - a relatively simple curses app - 56MB argocd - a cli for magaging argocd - 155MB

It's like what, $0.01 per GB these days? I bought a 2 TB NVMe for Linux 4 years ago, on which I also game, and it's 50% full. Disk space hasn't been a serious concern in two decades.

Until you start paying for it on cloud deployments per GB transfer.

Re: Go is my hammer, and everything is a nail

#797

Earlier quoted context omitted.

> and Java is shockingly bad too, although a lot of that is down to the way the JVM/language have been mismanaged This is interesting and not what I would expect. Generally to get a java app running from github you'd install the correct JDK and that should be about it. Many projects will use maven, which will know how to obtain dependencies. Could you describe a typical issue?

Dependencies requiring you edit some random XML file somewhere on your machine to get them working. That and the whole JVM fragmentation and not being able to touch Oracle because it's Oracle and they'll use it as an excuse to sue you (at least that's the impression I had, the entire lawsuits thing is why I left Java back in the day). You can say the same about other package managers, but it's not very often that I h…

Like the C and C++ compiler fragmentation, each with their own flavour of ISO support, UB and language extensions?

Or the Go compiler fragmentation, where only the reference compiler supports everything, tinygo a subset, and gccgo left to die in Go pre-generics era.

Re: Go is my hammer, and everything is a nail

#798

Earlier quoted context omitted.

> Instead of loading data into Pandas and doing a group by SQL can do `group by`. No need for overkill with "data science tools".

While definitely doable, using a SQL database to do data discovery is obtuse.

Depends, that is what OLAP is all about, naturally most of the good tools happen to be commercial for the enterprise space.

Re: Go is my hammer, and everything is a nail

#799
post #757
post #356

Earlier quoted context omitted.

Uh huh....and what comes next? Trying to descend more than a couple of layers into a GoLang JSON object is a mess of casts.

The same things that happens in JS or python. If you get a key wrong it throws (panics in go)

I wasn't talking about getting the keys wrong, but rather the insane verbosity of GoLang - `myVariable := retrievedObject.(map[string]interface{})["firstLevelKey"].(map[string]interface{})["secondLevelKey"].(string)` vs. `myVariable = retrievedObject["firstLevelKey"]["secondLevelKey"]`

"Oh, but that's just how it is in strongly-typed languages" - that may well be true, but we're comparing "JS or python" with GoLang here.

Re: Go is my hammer, and everything is a nail

#800

I used to work for a Go shop. We dealt with financial data. I found it so annoying that many of my colleagues would use Go for one-off tasks such as aggregating CSV files, updating the database with some data, or fetching data from the database, and then trying to make a plot. I saw my colleagues again and again implementing basic algorithms such as rolling median, or finding a maximum. Instead of loading data into P…

> rolling median, or finding a maximum The real question is why are you writing code to make a plot when you can load a csv in excel and get a clean plot in 2 minutes.

Because Excel sucks at plotting, especially if you have non-trivial amounts of data.
Post reply on HN