GoKart: A static analysis tool for securing Go code
brundolf 2021-08-19 00:16:07 +0000 UTC [ - ]
HALtheWise 2021-08-19 06:51:20 +0000 UTC [ - ]
nemo1618 2021-08-19 02:31:20 +0000 UTC [ - ]
jmnicolas 2021-08-19 08:38:28 +0000 UTC [ - ]
Why? What would be the point except as a personal challenge?
Zababa 2021-08-19 10:11:45 +0000 UTC [ - ]
pjmlp 2021-08-19 12:20:43 +0000 UTC [ - ]
Zababa 2021-08-19 12:32:41 +0000 UTC [ - ]
pjmlp 2021-08-19 12:50:43 +0000 UTC [ - ]
There are a couple of ways to compile .NET code into native code. Since version 1.0 NGEN was part of the SDK, although its main purpose was faster startup with dynamic linking.
On Microsoft side there has been CoreRT, NativeAOT, .NET Native.
Mono has had AOT support since ages and it is anyway required for iOS deployments.
Other than that several community efforts have taken place as well, for example WebAssembly.
Zababa 2021-08-19 13:04:36 +0000 UTC [ - ]
Thank you for the information on .NET AOT.
noisy_boy 2021-08-19 01:37:05 +0000 UTC [ - ]
still_grokking 2021-08-19 02:02:22 +0000 UTC [ - ]
But I've never used it so not sure how mature it is.
The other Go alternative I see is D.
Close to the metal but with high level features. Runs in a managed runtime. Creates native code.
noisy_boy 2021-08-19 07:29:01 +0000 UTC [ - ]
pjmlp 2021-08-19 12:23:45 +0000 UTC [ - ]
pjmlp 2021-08-19 12:22:11 +0000 UTC [ - ]
benhoyt 2021-08-19 04:50:27 +0000 UTC [ - ]
hardwaregeek 2021-08-19 00:39:40 +0000 UTC [ - ]
brundolf 2021-08-19 00:43:20 +0000 UTC [ - ]
I use Rust for a lot of personal projects mainly because of the type system, not because it doesn't have GC. I think GC's totally livable for a great many things, and it would help iteration speed a lot to not have to deal with the borrow-checker, but I just can't stand working in a language with a shaky type system these days. So Go-with-good-types sounds fantastic to me.
smabie 2021-08-19 02:05:42 +0000 UTC [ - ]
scns 2021-08-19 10:07:40 +0000 UTC [ - ]
brundolf 2021-08-19 02:21:19 +0000 UTC [ - ]
ggu 2021-08-19 03:53:06 +0000 UTC [ - ]
jacques_chester 2021-08-19 01:18:30 +0000 UTC [ - ]
brundolf 2021-08-19 01:27:16 +0000 UTC [ - ]
But if I saw it pop up on HN I'd jump on board in a heartbeat
Go has a lot of compelling benefits around compiling, performance, concurrency, etc that I think would translate. It just made a couple of really unfortunate decisions around null pointers and default values that turn a lot of people off. I think salvaging it from those unfortunate decisions would be worth doing for the right party with the resources to do so, and I think it would appeal to a lot of people
I'm not even sure I would want generics to be added, since that's an elephant in this particular room. I just want to be able to have a mote of confidence in the values I'm working with.
shp0ngle 2021-08-19 02:00:47 +0000 UTC [ - ]
ggu 2021-08-19 03:45:06 +0000 UTC [ - ]
jannetalex 2021-08-19 10:56:52 +0000 UTC [ - ]
the-smug-one 2021-08-18 22:09:12 +0000 UTC [ - ]
* Just a forward-style abstract interpretation living on-top of Go's type system as an additional layer so you get explanations for why the tool believes that a nil-pointer dereference may occur, etc.
SquishyPanda23 2021-08-18 22:55:41 +0000 UTC [ - ]
It still boggles my mind that Go decided to force programmers to worry about nil pointers.
tptacek 2021-08-19 03:53:09 +0000 UTC [ - ]
Which is fine, except that this is probably the second-most boring critique of Go, one virtually everyone has heard before, and it has little if anything to do with the story we're actually commenting on, despite having spawned a huge thread about option types.
If GoKart had been my project, I'd be annoyed.
nyanpasu64 2021-08-19 04:57:34 +0000 UTC [ - ]
- I dunk on Java for pervasive nullability too (though there are tools that add @Nullable xor @NonNull annotations used for analysis, possibly sound). But Go has over a decade more hindsight and should've known better.
I haven't used the other languages.
hnlmorg 2021-08-19 10:28:15 +0000 UTC [ - ]
Go distinguishes between the two too. You cannot pass nil as a value to int. In fact in Go you'd get a compiler warning[0] so you don't even need to rely on type hints and a properly set up CI/CD pipeline to catch said faults:
The problem with Go is that pointers can be nullable[1] as well as interfaces[2] (interfaces, crudely speaking, being Go's solution to generics and inheritance. Crudely speaking. So interfaces get used a lot).
There is some logic to them being nullable if you think about the code from a hardware perspective but given how opinionated the compiler and language is, I feel they could have done more to catch accidental nils to save the developer from having to consciously consider them each time.
[0] https://play.golang.org/p/BADNnw08hoo
[1] https://play.golang.org/p/b39tY1SDQtZ
[2] https://play.golang.org/p/Fsjsa_-o7Qb
maleldil 2021-08-19 13:08:14 +0000 UTC [ - ]
Basically, it's the difference between returning None from a function `def f() -> MyClass` in Python (which is type error) versus returning nil from `func f() &MyClass`, which is completely normal in Go.
Having `Optional` in the function signature makes it explicit that one has to check for Nones. Go lacks that.
hnlmorg 2021-08-19 14:35:43 +0000 UTC [ - ]
Plus I personally think if you need an optional parameter then 99% of the time the API is likely designed wrong from the outset (eg maybe you should instead be passing a class). The reason being is that optional parameters aren't always predictable (eg why is this value optional? When do I need to include a value for it?)
2021-08-19 05:20:37 +0000 UTC [ - ]
SquishyPanda23 2021-08-19 11:58:13 +0000 UTC [ - ]
I'm sorry you're bored and also annoyed in the possible universe where GoKart is your project. But it seems like this is a thing people want to talk about in a post about Go static analysis tooling.
I don't see why you're trying to police HN conversations.
pjmlp 2021-08-19 12:12:35 +0000 UTC [ - ]
logicchains 2021-08-19 07:16:41 +0000 UTC [ - ]
One of the common arguments now for why C# is superior to Java is that it supports non-nullable references. As does C++, which for large latency-sensitive projects is generally picked over C.
pjmlp 2021-08-19 12:14:21 +0000 UTC [ - ]
scns 2021-08-19 09:58:18 +0000 UTC [ - ]
Disclaimer: Using neither.
radicalbyte 2021-08-19 10:41:20 +0000 UTC [ - ]
The thing is, the Java ecosystem is insane. What else comes close to it in breadth and quality? Python, Go, Ruby etc certainly don't. C++?
pjmlp 2021-08-19 12:18:38 +0000 UTC [ - ]
Even on the places where Java and .NET languages took over C++ hegemony, it is still there on the implementation of native/extern methods and COM/UWP libraries.
Also don't forget if your favourite compiler is a LLVM/GCC frontend, many of its improvements require a bit of C++ code changes as well.
Nullabillity 2021-08-19 09:52:44 +0000 UTC [ - ]
drvd 2021-08-19 13:37:21 +0000 UTC [ - ]
SquishyPanda23 2021-08-19 14:04:21 +0000 UTC [ - ]
One piece of code from a well established tech company would just crashloop if authentication failed. I've seen others just die if the RPC service couldn't make a connection.
So in practice, yes I do have to spend my time tracking down nil pointer runtime bugs both from colleagues and also from other organizations.
SPBS 2021-08-19 00:49:09 +0000 UTC [ - ]
dabfiend19 2021-08-18 23:09:35 +0000 UTC [ - ]
streblo 2021-08-18 23:13:40 +0000 UTC [ - ]
magicalhippo 2021-08-19 10:45:37 +0000 UTC [ - ]
SquishyPanda23 2021-08-19 11:59:14 +0000 UTC [ - ]
magicalhippo 2021-08-19 12:11:53 +0000 UTC [ - ]
Is there really that much of a difference between those cases?
I agree though that in an interface, Optional conveys a more explicit meaning than something pointer-like, which is always a good thing.
SquishyPanda23 2021-08-19 13:38:11 +0000 UTC [ - ]
Go programs crash at runtime. In general, program failures and bugs should surface as soon as possible. Ideally no later than compile time. Instead, Go makes you wait until the app is running.
For an app that has a lot of configuration options, for example, there can be a latent bug that crashes the binary for some options. And that bug may not be detected for months because nobody was using that combination of config options.
The only real defense of this is to pepper your code with a bunch of nil checks. But these nil checks are also hard to test, so Go devs just learn to ignore missing code coverage. In fact, your code coverage metrics look better if you don't check for nil.
I'm sure at some point Go or a library will offer a version of optional types that is well-adopted. But my point is that by the time Go was designed, null references were already widely considered a bad idea and the source of a huge class of computer bugs. Go still deliberately designed them into the type system.
drvd 2021-08-19 13:43:00 +0000 UTC [ - ]
Well, of course, if your end users, the business users, are okay if you present them an "optional result" which might or might not be a result, then Optionals/Either _are_ the cure. Unfortunately most end users are pissed if you tell them that you optionally shipped their purchase or that the refund will either be credited to their CC or not.
logical42 2021-08-18 23:39:59 +0000 UTC [ - ]
Getting a nil where you are supposed to have an Optional.
mattnewton 2021-08-19 00:42:55 +0000 UTC [ - ]
tbarbugli 2021-08-19 02:16:56 +0000 UTC [ - ]
mattnewton 2021-08-19 15:45:51 +0000 UTC [ - ]
joshdev 2021-08-18 23:45:35 +0000 UTC [ - ]
still_grokking 2021-08-19 00:51:05 +0000 UTC [ - ]
In "pure" Scala (not in the FP sense, but just without mixing with Java) something like that is almost impossible.
marwis 2021-08-19 01:55:21 +0000 UTC [ - ]
still_grokking 2021-08-19 02:11:47 +0000 UTC [ - ]
For Scala 3 there are improvements. It's "null safe" as long as you opt-in (modulo Java libs, and of course doing stupid things like casting a null to some other type).
https://docs.scala-lang.org/scala3/reference/other-new-featu...
rowanG077 2021-08-19 01:04:37 +0000 UTC [ - ]
still_grokking 2021-08-19 00:54:02 +0000 UTC [ - ]
SquishyPanda23 2021-08-18 23:39:30 +0000 UTC [ - ]
pkaye 2021-08-19 00:04:21 +0000 UTC [ - ]
SquishyPanda23 2021-08-19 00:44:20 +0000 UTC [ - ]
If you don't need to manipulate pointers then nil really just represents a degenerate or optional value. For optional values these can be encoded any number of ways depending on the type system. One common pattern is an optional type. Another is to annotate the type to indicate that it might be null.
The idea is that if a programmer doesn't check that an nullable or optional type is missing then the program should fail at compile time instead of crashing at runtime. Golang chose to crash programs at runtime.
So for whatever reason, Go has decided that null pointer dereferences are not a big deal. But God help you if you try to comment out a variable use without assigning it to "_". Then the program fails to compile.
Zababa 2021-08-19 10:01:13 +0000 UTC [ - ]
I think that's a good explanation of why people are so frustrated with this. There are lots of features like go fmt, go vet, the compiler checking that you use all variables and all imports that can feel a bit restrictive. But for something like null pointers, there is nothing. It's incoherent.
masklinn 2021-08-19 06:49:52 +0000 UTC [ - ]
* separate pointer types (e.g. C++ pointers v references)
* a built-in sigil / wrapper / suffix e.g. C#'s Nullable / `?` types
* a bog-standard userland sum type e.g. Maybe/Option/Optional
In modern more procedural languages the third option often will have language-level (non-userland) facilities tackled on for better usability but that's not a requirement.
For cases (2) and (3) it can (depending on language and implementation) also provides a mechanism for making other value types optional without necessarily having to heap-allocate them.
mattnewton 2021-08-19 00:33:51 +0000 UTC [ - ]
izgzhen 2021-08-19 01:49:46 +0000 UTC [ - ]
masklinn 2021-08-19 06:52:47 +0000 UTC [ - ]