472 points · by Trisell · 10y ago · 218 comments
It isn't hard to prevent SQL injection if you use parameterized SQL statement rather than using string concat, and whilst examples of this are trivial they shouldn't be skipped.
In the XSS section it mentions filtering and checking inputs, but does not mention sanitization and does not give any examples. In the aversion to use any non-standard package it also does not mention https://github.com/microcosm-cc/bluemonday or anything similar (I am the author of bluemonday - a HTML sanitizer in the same vein as the OWASP Java HTML Sanitizer).
There is some sample code, in the Filtering section, but this only demonstrates the use of a fixed range of inputs in determining a filter, and then a regexp to check the input matches a format.
Beyond the security, where the theory is at least known even if a demonstration on how to implement it is lacking... the entire guide misses out on demonstrating templates to their fullest, and specifically using a map of functions to provide the equivalent of Django's TemplateTags.
In fact, the missing link for most Go developers who are building web apps, and for those coming from outside Go, are template tags. Most Go devs I know (who seem more systems focused) don't even realise that this stuff exists: https://golang.org/src/text/template/examplefunc_test.go
See http://www.more-magic.net/posts/structurally-fixing-injectio... and https://www.gnu.org/software/guile/manual/html_node/Types-an... for further explanation.
It could be that I just haven't come across any resources that do a good job of explaining their strengths. I see so many comments from people who seem genuinely excited about Go's built in templates that my assumption is always that I'm doing something very wrong.
Well, that perhaps isn't fair... fairer would be to say that there isn't an authoritative set of examples showing how people can achieve things similar to something like Django templating or Rails templating. It is actually fairly effortless to nest templates, extend them with custom functions, and all of the things one would need to do.
Probably one of the best resources is Hugo: https://gohugo.io/templates/go-templates/ and the funcs (template tags) they ship.
That isn't too bad at all, but the snippets and examples are so small that it's hard to really see what the value is and how it all glues together to create nice readable templates.
Anyhow, the key place to look at template tags would be:
1. Hugo's source code for template funcs: https://github.com/spf13/hugo/blob/master/tpl/template_funcs...
2. Hugo's creation of the func map: https://github.com/spf13/hugo/blob/master/tpl/template_funcs...
3. Hugo's documentation on the funcs: https://gohugo.io/templates/functions/
Those three things, viewed as one, should allow any Go dev to extend templates to do whatever you want them to do.
Hugo have been very "functional" in their choice of template tags, but there's huge scope for new packages to deliver more aesthetic tags, or tags for localization, to humanise time and plurals, basically to provide a core resource of tags similar to https://docs.djangoproject.com/en/1.9/ref/templates/builtins... so that each dev doesn't implement their own.
<extends main_with_feature_x>
<define title {{something}}/>
<define body>
... body goes here...
</define>
etc etcIncluding everything in every template just reeks of old school php. (Yes, I defend modern php : )
1. The password storage section where it gives MD5 as an option. MD5 should never be an option, not even in a simple testing / prototype application.
2. It actually calls base64 encoding encryption / decryption. This is really dangerous and outright wrong.
So if you ignore security related sections this guide overall seems good.
I agree with the practice of salt non-reuse, but it's not a part of the definition of. A nonce on the other hand does mandate non-reuse.
To start with - DES is broken, you cannot use it. It also totally blasts over important details like -not re-using the same IV- for AES. Really, it should be updated to use a better higher-level general purpose encrypt/decrypt library, which handles all the happy primitives in a way that you can't shoot yourself in the foot.
As for 'base64' being a good encryption algorithm? All the nopes & I can't evens.
The password stuff is pretty bad too. IDK, needs a re-write.
Web apps/services should use gorilla/sessions[1], securecookie[2], and Go's bcrypt/scrypt libs.
[1]: http://www.gorillatoolkit.org/pkg/sessions [2]: http://www.gorillatoolkit.org/pkg/securecookie
That is incredibly unfortunate especially since much of the guide seems pretty decent.
What's the hip solution for keeping a session-scoped, server-side data store? Recently dove into that for Hapi.js, found out that many people encrypt these and stuff them into cookies, ASP style - with all the same patterns of fail.
Also - the developers claim this is a feature (after all, you don't have to worry about load balancing or distributing your state information on the backend. sigh )
Cookies are also supported, and everything is HMAC'ed at a minimum. You can optionally encrypt, but since you should only be transmitting over TLS, doing so can be redundant.
But Go's not my goto language. I'm a staunch believer in the productivity of dynamic languages. In my opinion, Go's less than stellar type system and weak reflection capabilities exasperate this gap, even moreso for most websites / apis (which deal with impedance mismatch at two boundaries).
But, to answer your question. Consider first that Go's very simple to pick up. So the investment is small. Second, where I differ from you is on your second point: Java. I dislike it. It's complicated and verbose and gets in my way. Rust and Go are both proof that we know how to build better languages now. So, when I need to share memory across multiple cores and performance is a concern, I switch to Go because it's fast and simple.
> their goals, design philosophy and levels of abstraction are nearly identical
I think it could not be more different. Java APIs (including libs by Sun/IBM/Oracle) is a manifestation of more is less which is exactly opposite of Go.
> Java for more serious server-side software
The seriousness part is only because serious folks (the one who fund projects) prefer Java. I too think this is very important if not the most important part.
> unparalleled monitoring and tooling and more,
I too would need lot of monitoring and tooling if Oracle/OpenJDK GC keeps crapping out for just 10-20GB heaps which is currently the case for us.
I'm curious. Is there empirical evidence proving that Go is better than Java for small command-line apps, or did you just use your personal judgement to reach this conclusion?
Furthermore I think most people reach for Golang in the beginning because they want performance. However I've found it incredibly easy to write unperformant Go.
I think Golang will ultimately be a very important stepping stone in language development in terms of concurrency, type systems, standard libraries, deployability, and many other categories. I think a lot of important programs will be written in it. And ultimately I look forward to how future languages draw from it.
Some may argue that Go's simplicity is a strength. Adding moving parts doesn't always help.
"stepping stone" usually implies progress and Golang was a regression on both fronts, and while its deployment story is ok that's in no small part because it just opts to statically link everything by default, which the field has been going back and forth on basically since the beginning.
Plenty of JSON libraries in plenty of languages have both a function to decode JSON and an object that allows you to decode JSON with some settings. That's not really a Go-specific issue.
If you have time to spare read this: http://blog.paralleluniverse.co/2014/05/01/modern-java/
https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
One just can't write this shit in Go. The language itself precludes it.
Lack of very basic functions (map, filter, reduce) against slices.
map[string]interface{} is pain to work with (one of the moderately popular libraries I mentioned helps: https://github.com/karlseguin/typed)
Lack of immutability.
I don't want to get into errors vs exceptions, but I've never heard a pro-errors argument that wasn't hand waving. I think the decision makes sense given Go's genesis (system programming), but given how Go's actually being used, it's a step backwards.
Any non-trivial Go project will have interface{} sprinkled all over [1], which effectively gives you the guarantees of a dynamic language with the syntactic overhead of a typed language. Truly the worst of both worlds. While I realize it's a tired argument, Go desperately needs generics in some form or another. It would remove most criticism from the language while substantially improving the correctness of programs.
[1] Here's an example with an LRU cache. Just search for interface{} : https://github.com/hashicorp/golang-lru/blob/master/simplelr...
Go's compiler is very fast, which saves a lot of time in aggregate.
Go exhibits good design in many areas, including the core language, the compiler toolchain, and the standard library. You can write a complete server-side web application using only the standard library, and it won't be terrible.
Go is generally easier to learn than C++ or Java, and requires fewer concepts and fewer steps to produce a working program. A person who has written programs in Java or C can probably learn Go in about a day. Go's spec can be read in one or two sittings. The way to write "good" code in Go is usually obvious.
I've spoken to some detractors of Go and can understand where they're coming from. Erlang and Elixir users tend to not find Go's concurrency features compelling. Functional programmers will not find that Go provides much in the way of expressive power. Java programmers have expressed concerns about the Go garbage collector, although I think a lot of those concerns are now at rest.
For those that enjoy the set of tradeoffs that Go makes, it's a nice way to engineer software.
edit: typo
I really wish people would stop saying this. There is more to Go than just the syntax. I'm a Go dev on a team of php and Java devs, and just the opinionated philosophy of Go is hard to get across to them. They bypass the Go interview only to create the mess interviews intend to prevent. They are junior/mid devs again, except that because everyone keeps saying Go can be learnt in a day they think they've already mastered it. Go is easy to get started, but there is somewhat more than a day's worth of learning, I see this daily.
The only thing Go concurrency has over them is that it is easier to start with, but it isn't easier to use any other pattern, because Go doesn't allow library code to be first class in the type system.
The same thing goes for value types. In Go, everything uses value types. The standard library is littered with them. Will it be the same for Java? It seems unlikely, given that they have to keep backwards compatibility.
Granted, this is all from the point of view of an outsider who only dabbled in Java, so I may be way off base.
But mostly, you may find you just enjoy writing Go more than Java. It writes a lot like python... I switched from mainly writing C# to almost exclusively writing Go, and whoo boy, I'm not going back. No more huge class hierarchies, no more "everything has to be in a class"... no more "anything I call may throw and jump me out of my function in the middle and I have no idea if it will or not".
There's just a lot of niceties of writing Go that don't exist in Java. Sure, there's a ton you can do in Java that you can't do in Go, but once you stop focusing on what Go can't do, you realize, it still can do pretty much whatever you want.
Dropbox just rewrote parts of their Go infra into Rust explicitly because of the memory savings they needed.
Of course, if you have checked exceptions (which are for some unfathomable reason considered bad nowadays), nothing just throws an exception. Moreover, you don't know for sure whether a Go library correctly handles errors, because it's so easy to ignore them.
Any library that panics for reasons other than a programmer bug would never be used by the community. I read a lot of Go code and look at a lot of Go libraries, and I've never seen one that said it purposely panics in my 3.5 years of writing Go.
Compared to Java, C#, Python, C++ etc... where declaring your code panics is a perfectly normal and expected way to report errors.
it's considered bad practice in go library code to panic(), while it is considered normal error handling to throw an exception in java.
also note that you can catch a panic in go, and use it as some kind of exceptions if you really must.
https://github.com/golang/go/wiki/PanicAndRecover#usage-in-a...
For the most part, it seems to have gained traction in the Ruby/Python/PHP world as a backend optimization language. IMHO that's where it currently fits best for most people.
I see it being used for system tools, to some degree, because it requires no runtime at all (static binary). It also seems to be pretty popular for different newer data stores. Again, if it's pure Go it'll run anywhere... so it makes development (and portability) much easier.
I like its concurrency model, to a point. That said, I hope they really improve some things about in Go 2 (like working with channels and goroutines). I'm not sure when that will be.
I use Go for a lot of things, most of which are command line applications. Whether it be interfacing with some sort of REST API, taking actions on the local system, or some sort of network client for devices on my LAN. It works well for quite a few cases.
It seems to fit well with my mental model quite often, so I use it. And it's a simple language, so it was easy to get started with it. At the end of the day, it's a tool like many others. I think it's up to the creator to choose the tool that feels best to them.
This is something I haven't seen discussed much recently.
Do people generally think static linking is a good idea for things other than self-contained system-level daemons? (Where that daemon and supporting libraries might be the only thing you deploy to a server/vm/container)?
As I recently read in a (rather poor microbenchmark article) [1]: "The C assembly code I got with the following command is just 40 lines long. (...) The Go assembly code is 161.021 lines long which must be due to the static linking of Go.".
As everyone (should) know(s) any kind of language that lets you write a useful program in a page or two of code, will include a runtime of some sort (or be depressingly machine- and kernel-specific assembly code, and probably slower than anything a modern half-decent compiler produce). But I don't see a lot of discussion on how you make sure all your go daemons get updated with a new TLS/SSL/GZIP/PNG/XML-library when there's new serious bug found.
[1] Just included for reference, I don't really mean to pick on the author, but it's rather standard fare in the "quickly do a microbenchark; prove only that I'm wrong"-vein:
http://karlheinzniebuhr.github.io/en/2015/09/28/C-vs-Go-vs-p...
Yeah, I think it may be because it's situation dependent. For me, it always consisted of recompile all binaries and deploy them. And even then, I'm not sure people would enjoy a blog post just telling you to recompile all the things. It's not very sexy, honestly.
In my situation, it wasn't that big of a pain to do so. A lot of these libraries are within stdlib, so a security bug would incur a new release of Go. So an update should be pretty easy.
If's an external library (i.e., one picked up from GitHub for example), it's pretty much the same. Get new source, recompile binary with patched library, ship to all the things.
There are tradeoffs, absolutely. The alternative would be to write something in an interpreted language. That means we need to push a runtime environment up to the node, and that may include managing any libraries that are needed (think Rubygems). Managing these kinds of setups can be a pain, especially if a node has multiple projects with different dependencies. I found that shipping a single binary was often easier for me.
But it goes back to it being an item in the toolbox, depends on what you need and how your systems are built.
The servers dont have internet access and to get files onto them i have to do the same story as above (using sftp). So having 1 static binary that i copy over without having to worry about the dependencies is great.
"TLS/SSL/GZIP/PNG/XML"
all of these are part of the go standard libs, and gets regularry updated with the language.
tls and ssl: https://golang.org/pkg/crypto/tls/ gzip: https://golang.org/pkg/compress/gzip/ png: https://golang.org/pkg/image/png/ xml: https://golang.org/pkg/encoding/xml/
since golang also has built in support for fuzzing in the toolchain, the standard parts are quite battle tested already.
if you study their sourcecode you will also find Benchmark functions, that you can use to benchmark the implementations (go test -bench ./...)
So no, you shouldn't learn Go unless Go solves the problems that you need to solve. That said, as others have mentioned it's a pretty simple language and I found it quite easy to pick up and start writing programs in.
Indeed, if you already know Java, the only reason to learn Go would be if you had a burning need to produce self-contained statically linked binaries. For example, at my company, we have a habit of producing command-line clients for our services, and Go is a good choice for that.
Go has been most useful for people who know a dynamic language like Ruby or Python, but who are encountering problems where they need more performance, better concurrency, or stronger static guarantees. Go improves over dynamic languages in those respects, and it's pretty easy to learn, so it's a great addition to their toolbox.
Google is the perfect counter-example to your argument. C++, Java and Python were the 3 main programming languages in use at Google, and despite that, they designed Go and started using it instead of C++/Java/Python in some projects.
Go can be used instead of C++ when you need and can tolerate a garbage collector, and you don't need things like a custom memory allocator.
Go can be used instead of Java when you need a native executable, statically linked (like you wrote), when you need a better control over memory layout (especially to reduce pressure on the garbage collector), and when you need async IO without callbacks/promises/futures.
[1]http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/Fro...
Warranted or not, it usually fills the space where fast microservices are necessary.
Personally I think Go's closest competitor is Scala.
Coming from Python, Ruby, and TypeScript -- Go is a fair bit more verbose, and Java takes that a step further. So Go is a nice go-between from scripted environments to compiled.
I've never tried to make a whole web app with it, but it's great for making microservices.
Yea if you are doing any devops and want to contribute to or use consul/docker/swarm/kubernetes/terraform....
curious if rust has a hit project like one of those above.
I mean, eventually...hopefully...
Since confounding downvotes, a tldr: closer to Python than Java.
If you start having to Marshal/Unmarshal JSON, it'll get pretty annoying pretty quick depending on the JSON format.
For most web applications, JSON in or out is of a known schema, so this generally impacts other servers moreso than web applications.
One thing to consider is that the language is purposefully small, and you can learn the basics very quickly. Spend a day with it, and you'll get a feel for the language syntax and maybe some exposure to the standard library. You'll have a sense then whether you want to pursue it further.
So if you're curious, the compelling reason is that you can satisfy your curiosity without much effort, and that will ultimately be more satisfying than asking strangers to convince you one way or the other.
Go is drastically less bloated than Java. Stupidly fast compilation and running lets you use it almost (but not quite) like you might Python for some things.
A recent example for me: Writing a quick & dirty server that talked to a device that was spouting a stupid binary serial-over-TCP protocol. Goroutines made handling the bidirectional communication trivial, and go being a bit on the low-level side makes it easy to cope with binary protocols without worrying that your chars and bytes and unicode characters are getting all mixed up. You can do all this in Java - but it's so clean in Go.
My current playbook looks something like:
Network servers: Go. Go go go and more go. Things that talk to lots of other things and involve interesting communication are a natural match. I rewrote my pi searcher in Go a year or so ago, for example - http://da-data.blogspot.com/2013/05/improving-pi-searchers-s... - and this year was able to run the thing through Pi day on only a single (larger) AWS instance. Woot. We use it for research, such as writing Paxos derivates. Great stuff.
Go's also pretty amazing for little utilities if you want them to be faster than Python -- particularly if you want the launch time to be faster than Python. Which can be great for utilities you build to use in loops in shell scripts, etc. The fact that they're purely statically linked makes a lot of otherwise hairy cross-platform nastiness just go away.
The fact that it's statically typed and includes great, easy-to-use parsing support for itself also makes it much better for refactoring than Python is. The tools aren't as mature as those for Java, but the language is well-designed to support it (think "go fix" -- which can automatically port forward much old code to newer versions of the language). The tooling for this kind of thing is great for Java, good for C and Go, and absolutely horrible for Python. As a consequence, Go can more roubustly handle being worked on in very large codebases and teams. What would be a slightly scary regexp replace in Python can be a much more syntactically and semantically safe change in Go (at the cost of a little more writing of the replacement code).
Tensorflow (and most things numeric): Python. Because it was pre-decided. :) But, more seriously, Go's lack of generics hurt it here (you can't express matrix/tensor manipulation natively, and saying A * x is about as right as it gets when you're talking math). The ML community has adopted Python to a pretty strong degree, particularly because of NumPy, and so it fits in really well there. I still get grumpy about it -- I've lost count of the number of times I've messed things up that static checking could have caught, requiring quite a long time for tests/running it to finally do so. But I do like Python, to the point of:
Beginners: Python. I pushed hard to switch CMU's intro course for non-majors to it, and succeeded with a lot of help from others. It's awesome seeing what a bunch of motivated, smart first-years can accomplish in Python in one semester. Damn. And they can 'take it with them' -- scientists/engineers and numpy are a pretty good match, for example.
Fast as hell: C++, light on the ++, heavy on the C. A lot of our research code is very low-level. I'm still finding Rust incredibly annoying, but I may just be a slow learner, and it's on my list to take a really serious look at it after I'm back from Google.
(You'll note that nothing that I do involves a UI. I'm a unix & systems person through and through, which helps explain the utter lack of Java, C#, Swift, etc. in my life.)
Tensorflow has a minimalistic, but good-enough C API for running graphs. So, once you've built/trained a graph in Python, you can run it from Go without much trouble.
(Source: did that last week.)
still get grumpy about it -- I've lost count of the number of times I've messed things up that static checking could have caught,
For basic numpy-like functionality Armadillo and Eigen also work fine. I agree, I highly dislike numeric Python for the lack of type checking. Combined with the relatively long compile times of e.g. Theano it's a disaster (yes, I know 'fastrun').
I'm still finding Rust incredibly annoying, but I may just be a slow learner,
I'd encourage you to continue. I am also a beginner, but wrote some small crates. Once you get the hang off it, it combines the strengths of most things out there - C++-like memory control and performance, the terseness of Python/Haskell (though map/fold/etc.), and safety. It's a truly fun language to program in. Unfortunately, the library ecosystem is still rough.
You are writing most of your code in Go, so you don't really have practical knowledge of Rust. I recommend you to try start some project (or tool) in Rust, keep patience first month or two and then you'll love Rust. It's how came to Rust, now I'm in the "honeymoon" period with Rust and I love everything I do with it. Before Rust, I started thinking I'm losing joy in programming, by doing stupid and boring things every day.
I don't really see a reason why this should be the case, so I hope it will improve over time.
But using mandatory reference counting does limit the sort of tasks for which Swift will ultimately be suitable. I wouldn't put it in the same category as C++ and Rust for that reason.
Basically DIY everything outside standard library ( e.g. section 9.1 building CSRF) Personally switched to http://www.phoenixframework.org/ for json apis/web apps
There is little more to it than that.
here's an interesting article: http://www.whitesmith.co/blog/why-i-started-to-use-golang-mo...
[1] - http://www.wired.com/2016/03/epic-story-dropboxs-exodus-amaz...
* The standard library is really nice. It has almost everything you want and it's written in a clean non-enterprisey way
* It generates a single statically linked binary. Doing this is very difficult in most other languages.
* It's really really easy to cross-compile. Again, often very difficult in other languages (you might even have to compile your own compiler).
* It comes with a built in battle tested HTTP2 server, and a sane TLS library.
* It's a very simple language so it is easy for beginners to pick up, and also easy to read other people's code. Don't underestimate the importance of this - there's nothing worse than writing something awesome in a language that your coworkers find difficult, and then perpetually having to support it.
* The tooling is pretty good.
* Performance is good, and they've done really good work on minimising GC pause lengths.
Of course I wouldn't pretend there aren't downsides (cough generics), but they're mostly minor and certainly no worse than you'd have in any other system (C++/Python sounds like it would have more than its fair share of issues!).
Edit: Aside from generics, my biggest complaint is the impossibility of RAII. It's too easy to forget to `close()` things. Most languages suffer from this though, and at least Go makes some attempt to improve matters with `defer`.
For AOT platforms it's difficult mostly due to glibc. e.g. on FreeBSD and Linux musl it's trivial to build fully static binaries.
Otherwise all valid statements and Golang is an improvement over other mainstream languages. So here's some future items for improvement that would make it even better and well suited for wider use:
* a nicer error handling mechanism, though this may be hard
* dead code elimination. Golang's static binaries are huge compared to fully statically compiled executables for other languages. I suppose the new compiler passes and backend might provide a basis to solve this.
* restore compile speed, which of course was mostly due to previously missing optimizations and simple compiler passes, which were added now and made it slower. Still the Wirth'ian language design allows for much faster compile times than C or C++.
To define a bit more what I mean by "low-level":
- I think that Go is "lower" level than Java because Go is compiled to a native executable (no virtual machine) and Go gives you control over memory layout (not everything is a reference like in Java).
- I think that C/C++/Rust are lower level than Go because you control memory allocation and deallocation (no garbage collector) and you can even customize the memory allocator if you need. It's also more efficient to interface with C libraries because the calling conventions are identical.
However posts that, in 2016, seriously posit "I'm trying to figure out if it's worth learning" I don't believe are being sincere. They're usually saying "I haven't, and still don't want to, and here's my current justifications". And that's okay. I don't know Rust. I haven't bothered with Swift yet. One day.
And when you need third party libraries, then other languages have much more mature libraries[1], and thanks to more powerful type systems, those libraries get to be used almost as built in types.
[1] TPL, TBB, PPL, java.util.concurrent, Quasar, Cilk, C++AMP, Akka, Akka.NET, Orleans, ...
Most of the Go references that I tend to come across tend to focus on code, concurrency and API's without much attention to the full stack web app side. This definitely helps to fill that gap in the community.
Just flipping through the contents and skimming the chapters, the IDE section alone is really impressive.
To those with suggestions related to e.g. security pratices, step up and contribute!
The fact that this books advertize "build your own orm" solution, with the one given not even able to select 1-many objects makes me really wonder how in the world one could recommend go for web apps.
Ps: to get a benchmark on what is the current level of productivity expected today for enterprise-like web apps, just have a look at a loopback.io demo. Yes, it's node.js which sucks, but you have to admit that we're pretty far away from manually mapping result columns to struct properties.
Like
// define a slice with 10 elements whose types are bytes var ar = [10]byte {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}
For those, other languages like Java and C# that better support encapsulation and data/information hiding for the modeling of real-world concepts remain suited.
I think the problem with a lot of language discussions is really about the need for many to find the "one true ring" that can be learned and applied everywhere.
Instead, a polyglot approach surely is the best one?
I think it serves as a good example of how one can use go for webapp development.
With that said, after a year+ of writing go in my day to day job, I still gravitate towards dynamic languages for web application development and leave go for most systems programming tasks.
I'm not trolling. It seriously is easy enough to crank out a basic web app in less than a hundred lines of code that runs very well with just the standard library.
In addition, there is also: https://github.com/gorilla/mux , which complements net/http very well.
A Go program listening directly to port 80 running as root?
What about virtual hosting, https, load balancing and so on?
I like to use https://caddyserver.com/ as reverse proxy for the easy setup and buildin Let's Encrypt support. You can also use Apache or Ngixn if you want.
But you can also bind directly to port 80 if it's a simple app.
If you have to write explicit code in each of your postbacks to check a CSRF token, it's going to happen that not all your posts will end up being protected. If you have to hand-build SQL queries, it's going to happen that you'll have injection vulnerabilities. If you are manually generating and signing cookies, and having to write explicit code to sign them and check signatures... These are all features that should be done in a core library which makes sure these things happen all the time, not just when you remember to, what, copy/paste the code into each of your functions to do it?
There's the overall structure of the code, which seems like it would quickly devolve into chaos. Looking at Section 4.4 there's a 'login' function which handles rendering the GET as well as processing the POST just by if/else on r.Method. You wouldn't want to actually structure a code-base like this, right? Later on, they do show a 'Beego' based router, which seems a bit more sane, but I'm really not a fan of 'showing the wrong way first' as a learning tool.
The particular techniques being used seem very home-grown and not particularly best practice. To prevent double-submit they add a hidden field with token=MD5(time.Now) and also save it to "a session cookie on the server side"? Not quite sure what that means, but I think it's trying to say save the token on the back-end linked to the session, and then verify a POST, from that page, on that session, has that token. And then presumably clean up the storage... The majority of which is not actually coded in the example, making it just a high level roadmap of what you could do, not a practical working starting point. But anyway, if your goal is to prevent multiple POSTs per GET, and you already have a transactional session state for the user, then you do it with a server-side counter, not a hidden field, and certainly not a "obfuscated" MD5(time.Now). Even if you have no session state, then the simple answer is to create session state, not to create another token which does exactly the same thing as session state, but in a completely insecure manor.
So overall I have a ton of respect for the work that was put into this document, it tries to cover a lot of material and is very easy to read. But I think the details also matter and 1) I can't believe this is idiomatic Go for how to actually route and manage requests, and 2) the entire proposed tool-set for actual secure processing of Sessions, SQL, CSRF, XSS, etc. seems to be totally home-grown and not at all production ready.
Is it super sexy, no. Does it win me Internet Geek Points™, no. It's pretty much still Windows-only, but fine, that's the world I live in. The foot-guns are relatively small-caliber, and I've learned enough to avoid pointing most of them. I can do OOP, I can do functional (maybe not super pure ivory-tower monad/ADT/pattern-matching sorcery, but whatever - still have F# on my todo-list...), I can write straight procedural code if I really wanted to. I've even got a REPL and can use it as a scripting language.
Plus, I have generics :-)
While I understand that HN has quite a population of .NET platform devs these days, traditionally this sort of noisy comments would be quickly rendered transparent (this one even claims to justify itself relative to a "language shootout"....only it's just a page talking about Go best practices, so it is off the mark). And the "Internet Geek Points™" thing is just nonsensical, and has become another defensive .NET talking point (e.g. "We're not trend chasers...now let me tell you how we also incorporate all trends").
I would have ignored it, but the above "language partisan" comment, having utterly nothing of value to add to the comments, or this story, and being completely out of context, has been floating on the top, betraying a pretty profound twist in the saga of HN.
Voting based on insightfulness or relevance simply cannot work when only a small minority can ever be expected to stick to it. We are being conditioned on picking a side and then boosting that side no matter what.
Voting up a comment that is in disagreement with your own opinion makes it look like you are losing the debate if being upvoted is generally associated with being right. So most people won't do it.
I believe the only way to prevent this in a community is to force people to use only words to express opinions. In my view, voting has no place in debates. And yes it means that we're not going to get our debates filtered and ranked according to insightfulness. But at least we're not getting any false signals based on perverse incentives either.
And yet, I just upvoted your comment because it seemed much easier than typing a reply to say that your comment was of interest to me and I enjoyed reading it. But now I've said that as well.
I like having the flexibility to do both, but I recognize the compelling arguments you've made about the problems with having voting available everywhere. On HN in particular, I feel the downvote capability should be further constrained than it is presently (I think it opens at 500 karma presently).
People invest time in their languages so it's easy to subtly inject emotions into comments that come off snarky and unproductive. Then other supporters of the language just defensively click the up arrow.
There was a lot of this in the WASM articles where they were saying it will kill off Javascript.
Many of us are happy in our niche, and learning new things is often a PITA. We're happy with what we do and how we do it, with the tools and things that we're used to. And that's okay. The truth is that the language evolution is something that we can mostly just ignore, and if eventually something is truly dominant for a use case, we can easily adopt it with no real handicap over people who ground with it from the ugly beginnings (and many of those advantages will percolate to other platforms anyways. node.js is just layers and layers of compromises and problems, but it had a profound impact on other platforms, and truly changed the web serving game).
And that's okay. But traditionally if someone posts resources for a particular language, it is bad form to engage in language wars, gloating, holier than thou (which the whole scarequote "maybe it isn't `trendy'" sorts of posts really are), etc, in the discussions. They're boring, we've had them literally thousands of times, and they are a distraction from discussing the actual contents of the post.
I've noticed this particularly afflicts Go discussions. Python, Rust, D, Swift...all can be discussed rationally and productively. But if Go appears, it seems to be just threatening enough that it draws out people concerned about things they don't know.
First, a quick rant. You talk about "great tooling," and by this (I fear) you mean Visual Studio? Good libraries, by this you mean things like System.Foo.Bar.BazQux()? A "decent core language," by that you mean a pretty blatant knock-off of Java (which is an overly-bloated language in its own right)? And by "can do OOP" you mean must do, since the language forces you to embrace the paradigm? "Functional?" Without real first-class functions: without closures?
Generics? Fair point. Golang is lacking in that regard, at least for now.
But let me address the key misconception in your comment. You mention "sexiness," which in your mind is some sort of pointless quality. Here's what you're missing: biologically, we interpret sexiness as an indication of fertility. Good tools and languages aren't good because they're sexy, they're sexy because they're good. The ability to perceive, expect and demand this sexiness from tools is nothing more than a veiled desire to work in the most effective possible way. That's why people love Unix and hate Windows. That's why they leave languages like Java, C#, and C++ for Python and Go; and some (who I admire) use Haskell. It's not about elitism, the elitism is merely a by-product: the fundamental issue here is greediness, and the strength of one's desire to be as efficient as possible.
With regard to sexiness, as an old Quebecois logging foreman once told me, "Sometimes you want the supermodel wife, and sometimes you want the one who can carry the canoe." If you can get both, great, but I got a lot of canoes to carry.
> Honestly comments like these further discredit the Windows-development-community in my view.
I'm just an asshole with an opinion on the internet, and I seem to have misplaced my official Windows-development-community membership card...
Programming language flamewars are bad for this site. They're tornados of tedium that pick up entire threads and deposit them miles away in an intellectual desert. Please let's keep them off HN.
And C# is sexy, it's the best object oriented language out there. So don't worry. C# doesn't need yet another guide for web apps, there are thousands of books and tutorials about the subject already. You don't need to try selling C# to anyone. People who need it already use it.
In the next 12 months with the release of .NET Core, even the Windows requirement will go away. It should be at the top of the list for just about any project these days.
As another poster already commented; > You don't need to try selling C# to anyone. People who need it already use it
"Need" is a funny way of framing your counter. Of course any one who "needs" it, need meaning they can't use something else, would be using it. However there are many who would very much LIKE to use it but can't because the Core stuff is not quite ready for them; I NEED for it to work on OSX and linux but as of the latest dotnet deb package I can't use the AWSSDK with it.
Why not? I'm not selling anything. I just listed some reasons why C# is a great language with a great framework that can be more productive than most other environments.
By the way, it's probably one of the most commonly used languages ever when looking at the entire amount of software that's written in the world. Basically the entire Fortune 500 runs software written with .NET/C#.
"one-day" is today.
There's a time to play with new shiny objects, and there's a time when you have to get real work done.
If anyone here hates on you because you can get shit done with your preferred language...they're just jealous of your productivity.
I've done C# development for many years. C#, while elegant, is far from being a productive language, mostly because of its ecosystem and community. Making a simple API web server using proprietary Microsoft libraries is way harder than it needs to be. Documentation is also piss-poor on most of these tools, and many developers just resort to reading opinionated online web blogs which give all kinds of terrible advice. You can use open-source libraries like Nancy instead, but they're usually error-prone and updates have been known to break production deployments.
Visual Studio still crashes all the time and compilation on bigger projects is usually slow and painful. I've had to work on full fledged projects with infamous Entity Framework data-access layers and these things are a nightmare to work with. I've seen entire projects generated using T4 text templates...
As feature-rich as the language may be, the way developers use it lead to huge problems. Now that Microsoft is introducing ASP.NET Core the fragmentation in the community is only getting worse. Couple this with the fact that .NET is used in all sorts of dysfunctional development teams, and you've got a recipe for disaster every time.
C# is not a productive language.