6 ms·
From the article: Go is "safe" by default. Pointers cannot point to arbitrary memory, and buffer overruns result in crashes, not security exploits. That's only
by Animats 12y ago
From the article: Go is "safe" by default. Pointers cannot point to arbitrary memory, and buffer overruns result in crashes, not security exploits.
That's only true for single-thread Go. Go is not memory-safe in multithread mode, because exploits using race conditions are known.[1] This, incidentally, is why Go is locked down to one thread when running under Google's AppEngine.
Go is a good language for server-side web work - all the expected libraries are there and in good shape. That makes sense; that's why Google had Go created. Go is a good option when Python and Javascript/node.js are too slow. But Go's concurrency isn't as clean as its enthusiasts claim.
I'd recommend Go for programmers coming from the Javascript/Python/Perl world. Although Go is a hard-compiled language, it's surprisingly similar to the scripting languages when writing routine server-side code. C++ programmers will find Go easy, mainly because it's garbage collected.
(The replacement for C++ will, if we're lucky, be Rust. Rust has roughly the complexity level, headaches, and gotchas of C++, but it catches all the memory-related bugs at compile time. Rust isn't ready for production use yet, though. Give it a year.)
[1] http://research.swtch.com/gorace http://research.swtch.com/gorace
- mempko 12y agoI have already replaced C++. C++14 has already replaced C++98 for me.
- pjc50 12y agoCan you ban "native"/bare pointers in C++14? And C-style casts?
- plorkyeran 12y ago-Werror=old-style-cast will make C casts an error in gcc and clang.
- nly 12y agoand -Wconversion and -Wsign-conversion coupled with the new C++11 {braced} initialisers deal with a lot of bad implicit conversions inherited from C
- detrino 12y agoUnfortunately this can be problematic if you include any library headers that use old-style-casts.
- plorkyeran 12y agoUsing -isystem rather than -I makes gcc/clang not emit warnings for headers found in those paths, which does extend to -Werror.
- detrino 12y agoThanks for the tip.
- cannam 12y agoThe one time I still use C casts in C++ is when comparing an int against the size of a container: if (i < (int)container.size()) This is because container.size() returns an unsigned type, and I try to avoid unsigneds in everyday code, and I like to use -Wall -Werror which, amongst other things, produces errors for signed/unsigned comparison warnings. I don't want to have to make the variable "i" unsigned, because using unsigneds for anything other than bit arithmetic is quite hazardous in practice (http://soundsoftware.ac.uk/c-pitfall-unsigned http://soundsoftware.ac.uk/c-pitfall-unsigned). How do others resolve this problem?
- mappu 12y agoYou've traded one hazard for another there, now you have a bug at runtime if the container size is between the range of signed int and unsigned int. Hope that container size isn't user controlled. I'm guilty of a few C-style casts, but certainly prefer catching things at compile time than runtime. So +1 unsigned types for me. At least the compiler helps with catching signedness issues.
- cannam 12y agoDoes the compiler help? $ cat unsigned.cpp #include <iostream> void f(unsigned int x) { std::cout << "x = " << x << std::endl; } int main() { f(-1); } $ g++ -Wall -Wextra -Wconversion -Werror unsigned.cpp $ ./a.out x = 4294967295 No error, no warning. The two are not really distinct types. See the link I posted above for more argumentation along these lines.
- shin_lao 12y agoYou should use static_cast<>() and not C style cast. You should not care about signed/unsigned, use auto.
- cannam 12y agoI would prefer to use auto when iterating through the container, certainly. But much of the code I write is numerical stuff and "i" really is logically an integer rather than an iterator, arising as the result of some actual arithmetic. I find I have to do this quite often, and I'm not going to write static_cast<int>() every time. Yes, I can see why this isn't a good idea -- I'm pained by it myself. I'm just wondering what I might have overlooked among the possibilities available for this kind of code.
- cyber1 12y agoVery interesting article http://research.swtch.com/gorace http://research.swtch.com/gorace, but it's very old, published in 2010. First Golang stable release r56 in 2011/03/16 https://golang.org/doc/devel/release.html https://golang.org/doc/devel/release.html.
- tptacek 12y agoThis article comes up every so often on HN, and it's great, but the people citing it tend to muddy its argument, as you've done here. The "exploit" rsc is referring to here is hypothetical. To wit: if there existed some service (like multithreaded GAE, or an especially weird browser) that allowed content-controlled Golang code to run, that code could exploit mutability to violate assumptions made by other code, in much the same way as you could by dropping down to "unsafe" in Golang and Rust. For that vulnerability to matter, you have to suppose a system that rigorously constrains the runtime to block system calls, containerize I/O, shut off the "unsafe" APIs, and somehow fence off state for crypto. Nothing does that. Real-world systems that allow users to upload arbitrary Golang code give up on protecting the runtime, and use OS-level protections to maintain integrity. I agree that Golang isn't a great fit for C++ programmers. If you're still writing C++ in 2015, it's because you're productive using all the bells and whistles C++ provides. Golang is very much a one bell, no whistle language.
- heinrich5991 12y agoIt just means that Go isn't memory-safe by default.
- Animats 12y agoFor that vulnerability to matter, you have to suppose a system that rigorously constrains the runtime to block system calls, containerize I/O, shut off the "unsafe" APIs, and somehow fence off state for crypto. Nothing does that. Google AppEngine does exactly that.