9 ms·
Learn Go by writing tests – Hello, world (2018)
- ChristianGeek 6y agoWeird choice of link. Try this instead: https://github.com/quii/learn-go-with-tests https://github.com/quii/learn-go-with-tests Or this if you really want the Hello World example: https://github.com/quii/learn-go-with-tests/blob/main/hello-world.md https://github.com/quii/learn-go-with-tests/blob/main/hello-...
- fhunt 6y agoOT but it this decade not more about types than tests? Edit: Since this seems to be an unpopular opinion why stop here, haha: The more one stresses tests the more he/she signals that he must have missed years of advancements in software engineering. If you do this with peers, ok, but publicly? Even Ruby added types, not the kind of types we hoped for but still, it's a strong signal. If your lang has a mature type system you don't need half of your tests anymore and might not be into such write-ups. Praising and writing gazillions of tests don't make you look smarter, very much the opposite.
- quii 6y agoI'm not sure how they're mutually exclusive. Also TDD is more of a _design_ technique than a testing technique. I've worked in languages with extremely expressive typesystems (like Scala) and I still practiced TDD
- fhunt 6y ago> I'm not sure how they're mutually exclusive. Where did I say that? I just meant, and my apologies for not being clear, focus should be types, ofc you still need tests. But not as many as a decade ago and more important, people must drop this dogma that tests are the key to everything. There are not and the more tests a codebase has the worse its quality and maintainability. > I still practiced TDD You can do this ofc but my experience differs: Once you have an excellent type system, both in terms of language features and tool chain eg editor, you can literally code for days without running even the compiler once. This is pure flow and very much the opposite of TDD. But the entry barrier of is much higher than TDD. Don't get me wrong, you still need tests but TDD?? IDK, this feels like trial-and-error-coding from 2010. I mean if we still used all Ruby, yes tests and TDD everywhere but the environment has changed.
- eterps 6y ago> both in terms of language features and tool chain What would you give as examples for language features and toolchains that enable the workflow you are suggesting?
- fhunt 6y agoTS has by far the most advanced compile-time type system followed by Rust. TS has the best and most responsive editor support (tsserver). I know that Rust's is much slower but IDK much more than that. Re ecosystem and build system: TS' build system is not trivial but it's very flexible and has a bigger ecosystem.
- valenterry 6y agoIdris and F* have a much much more advanced type system, compared to Typescript and Rust. But even if you deem these languages not "mainstream" enough, there is still e.g. Scala which has a typesystem that beats the one of Rust by far and also the one of Typescript, minus certain special cases where Typescript is really nice. It is great to see though that even frontend-mainstream languages like Typescript start to get proper support for type-systems (especially considering that they had to do it on top of Javascript). Very excited to see where we go with languages and I agree with you that TDD should now by default mean "type driven development". :)
- Cthulhu_ 6y agoIt should be both, I think. Types take away part of the need of tests, but they're not mutually exclusive. I know I ended up writing a lot more tests when doing Javascript, just to cover type edge cases.
- kayza 6y agoHere’s the link to the GitBook https://quii.gitbook.io/learn-go-with-tests/ https://quii.gitbook.io/learn-go-with-tests/
- davidspiess 6y agoI recently began learning Go and i was pointed to this site. I worked through all the chapters in the book and was pleasantly surprised how engaging it was. Definitely recommend it to other newcomers.
- trm42 6y agoDid most of if out of curiosity. Really nicely done and well written. Really approachable for a total golang-newbie.
- henvic 6y agoWhy do some people use spaces when writing Table Driven Tests with Go? It makes it harder to run go test -run=TestName because you have to convert manually all " " to "_" and back. This is at least a great reason why this 'test name with spaces' pattern isn't found in the standard library: https://github.com/golang/go/search?q=t.Run https://github.com/golang/go/search?q=t.Run
- insertnickname 6y agoI_don't_know_why_we_even_have_spaces._Somebody_tell_me!
- henvic 6y agoOh, so what about having spaces in your function names too, if you like spaces this much?
- danbruder 6y agothis is such a great resource, highly recommended