Better HN
topnewbestaskshowjobs
Log inSign up

NateDad

2,023 karma · joined Sep 12, 2012 (14y ago) · 1,061 submissions

Real name: Nate Finch Software Engineer since 1999 in the Boston area. natefinch on github.

[ my public key: https://keybase.io/natefinch; my proof: https://keybase.io/natefinch/sigs/4vluNroUMrNptUZ0-yf__o_BjbNO7CcrsudVWRG5Xc0 ]

Submissions

comment 7y ago · link · parent

....in Go?

comment 7y ago · link · parent

Man you Go haters LOOOVE to trot out that quote from 2014.

But you know what, go is easy to learn, and that's been awesome in my experience. I can (and have) hired people who have never written go, and they're productive in a week or two.

comment 7y ago · link · parent

Oh, oops, yeah, I misread "some" as "same". Denoting what contract they obey is just the name, isn't it? T1 and T2 are names of contracts.

I guess what you can't do by just using the contract name is say that two arguments must be of the same type. Nevermind.

comment 7y ago · link · parent

They'd both be T1 in that case. T1 T2 means they're different contracts.

comment 7y ago · link · parent

not if each one can fail. What if call #1 and call #3 can return the same error.. how does the caller know which one failed? This is the same as wrapping a bunch of calls with a catch (Exception) ... you lose context of what failed and can't behave differently for different failures. All you can do is perform a generic "something went wrong" behavior.

comment 7y ago · link · parent

I really dislike method chaining. I'd much rather have 5 lines than 5 chained methods. If that's too much to read, you can always encapsulate it in a well-named function.

comment 7y ago · link · parent

Try makes it worse because it is so easy to miss when reading the code. Because it encourages nesting function calls, which is harder for a human to parse than separate statements across lines. Because it means you can exit the current function from the middle of a line of code, and what runs before or doesn't run before is based on order of operations rather than requiring the exit to be a statement on its own line whose order cannot be misunderstood. Because it discourages giving more information with an error, so instead of "failed to open config file: EOF", you just get the EOF.

Go's error handling isn't any more error prone that writing if statements for all the rest of your code. if err != nil is no different than if age < 18. Either one is a branch in the code. I can literally count on one hand the number of times in 6 years of full time go development that I've seen people miss writing the if err != nil.

Being explicit is good. Spreading out the logic is good. Cramming a lot of logic into one line is bad.... and that's the sole purpose of try.

Maybe there's another way to make error handling better in Go. I'm not averse to looking into that. But try wasn't it.

You're talking about writing if err != nil being tedious, but what about matching Results from Rust, isn't that tedious? What about writing proper catch blocks in java or C++ or python, isn't that tedious? It's all just logic.

comment 7y ago · link · parent

Literally the first non-trivial code I wrote in go (running a bunch of goroutines to download a ton of files from a website in parallel)... I knew exactly where and how things could fail and where things were failing just by looking at the code. Coming from C++ and C# and Python, there was no comparison. I had never been so confident in the code I'd written, even though I was a newbie at Go and a veteran of the other languages.

comment 7y ago · link · parent

Functions are a thing. Interfaces are a thing. I have literally never, in 6 years of full time go development, just copied and pasted code for the purpose of making it work with a different type. Nor has anyone I have worked with in that time (to my knowledge). I have seen two or three libraries written that use interface{}, but these are by far the exception.

comment 7y ago · link · parent

A simple text search will find it every time. Since Go code should always be formatted, it's pretty trivial to search for `type HTTPServer` or `func NewServer(` ... even over fairly large codebases this will give few enough hits that you can just search everything most of the time.

comment 7y ago · link · parent

I've worked on a million line Go code base and a dozen open source projects and many typical backend services, and interface{} is actually quite rare outside of something like json serialization or string printing - i.e. fmt.Printf(msg string, args ...interface{})

I almost never see code that application developers write using it, and usually if someone is writing that code, it's wrong, and I help them figure out how to avoid it.

Usually you can avoid it by using closures or interfaces.

comment 7y ago · link · parent

This is just not true. 2.5 years ago when I was looking for a remote-only go job, I had so many positions to look at, I had to put them in a spreadsheet. None of them were in silicon valley .

Many many places are using go here and there. From start ups to big enterprises.

It's rarely all they do, but it's pretty common to have some backend in go.

comment 7y ago · link · parent

I worked on a million line go codebase for 3.5 years. It was readable and consistent and actually quite nice.

comment 7y ago · link · parent

    names = append(names, "Bob")
.... that's really it. Will it have the same backing array as it did before you did append? Maybe, maybe not. Should you care? Absolutely not, and if you do, you're probably doing something wrong.

comment 7y ago · link · parent

I've been writing Go for over 6 years. Error handling at the source of failure is a feature, not a bug.

Rob Pike's example code is bad and I would not allow it through a code review. Why? It makes the code lie. It appears as though the writes cannot fail, but in fact they can, and later writes become no-ops. On top of that, it means that you lose the context of which write failed. Did you fail writing the header, the body, or the footer? You can't know anymore.

This is like

   try {
        doThing()
        doThing2()
        doThing3()
   catch (Exception ex) {
      // handle
   }
You can't tell what failed. You can't tell what is possible to fail. The handler can't differentiate.

comment 7y ago · link · parent

C# has the feature-bloat of C++, except with a garbage collector. (I wrote C# for 9 years and even when writing it 40 hours a week, I still had trouble keeping up with all the features that continually came out)

comment 7y ago · link · parent

I wrote a generic version of cog that can use any language as the generator code. It's called gocog, because it's written in go, but once compiled, it's a static binary, and you don't need go on the host machine.

https://github.com/natefinch/gocog

It's directly built off of cog's ideas and mimics much of cog's interface. (I worked with Ned, cog's author back in the day, and really enjoyed having cog to write boilerplate for me).

gocog is some of the first code I wrote in Go, so it's not super pretty code, but it's a very useful little tool for generating boilerplate.

comment 7y ago · link · parent

I think the author understands exactly what they're talking about, and they're not talking about being employee #1-3.

Most people, when they hear "work at a startup", they're talking about being employee #10-30. Not 1-3. There are, clearly, 1/10th as many of the latter, and they're almost all looking for much more skilled people than employees #10-30. I figure this advice is for people who are newer in their careers. People with 10+ years experience probably already know what the article says, and they're likely the only ones who might get hired as employee #1-3.

comment 7y ago · link · parent

C++ versions are never correct

comment 8y ago · link · parent

If you care, you can't realistically forget. There are linters that will find your missed error checks.

comment 8y ago · link · parent

Gah, my eyes! Why is the font so huge? And why doesn't zoom change it? I have to like step 5' back from my screen to read it....

Otherwise...

I have been writing Go for about 6 years... errors make so much sense to me. Why have some external codepath for "file not found"? Why is that different than "name == bob"? They're just data that is in one state or another. You check for them the same way, with an if statement. There's nothing magical.

22.

Mage – make/rake for Go(npf.io ↗)

8 points · by NateDad · 8y ago · 2 comments

comment 8y ago · link · parent

IF you have a 500k LOC software project... how the heck is an SRE/devops person going to figure out where in that code a specific configuration item is going to be used? They're not. This is why documentation is essential for projects. You could keep configuration documentation in a separate file... but that only helps for what the config does. It can't help you figure out why Bill (who left the company a while back) set ThreadMax to 650 when he changed the code 6 months ago. There cold be a commit message that references it, but that's more disconnected from the change that just slapping a comment on top that says why.

I agree that code review for configuration changes is necessary. That same code review process can ensure that the comments in the config file are also correct.

comment 8y ago · link · parent

Hugely disagree. Config files will modified by non-experts of the application 1000x as often as the actual developer of the application. Those people won't and often can't go look at the code.

Also, it can be really hard to find where exactly a configuration value is used. You may have to trace through a ton of code to find the place, and then you can't be sure that's the only place it's used.

Configuration comments are crucial, both for onboarding new users (explaining what the default is if you don't set a value, explaining what the configuration value actually controls, etc) and for experienced users to tell others why this esoteric configuration is set the way it is.

A configuration file is literally just a stack of magic numbers and strings. Why are we setting threadpool to 10 and not 1000? Why are we disabling X feature? What the heck does TPS_Report=true do?

You need comments.

comment 8y ago · link · parent

Getting the wrong password in your password manager happens occasionally. Usually from password resets that somehow don't make it into your password manager. The fact that HN allows accounts without email addresses is the real problem. Also, maybe he just doesn't value his HN account all that much.

comment 8y ago · link · parent

It's like your own personal google drive / dropbox / git repo

It's a content addressable storage system. There's plugins to import or export from various major services like foursquare, twitter, etc. and plugins let you store stuff in S3 or mongo or google cloud storage, etc.

comment 8y ago · link · parent

hell no. Rule #1 - users should never see stack traces. Every time some python tool fails and dumps a stack trace, I want to throw my computer across the room. As as user, I never want to see a stack trace. I have zero interest in debugging some random tool. Show me a decent error message with tips on how to get more info. If you want a stack trace that I can give in an error report, put it in a log file somewhere.

comment 9y ago · link · parent

Not sure if you're talking to me. I was saying that NullReferenceExceptions happen a lot more in C# than nil pointer panics in Go.

comment 9y ago · link · parent

Yes, which is not error handling. Exceptions automatically handle error propagation, which is not the hard part of dealing with errors.

comment 9y ago · link · parent

Your compiler can't handle errors for you. Error propagation is not error handling.
12345
36