[HN Gopher] Build Pong in Your Terminal with Go for Some Reason
___________________________________________________________________
Build Pong in Your Terminal with Go for Some Reason
Author : jalletto
Score : 119 points
Date : 2022-07-26 14:03 UTC (8 hours ago)
(HTM) web link (earthly.dev)
(TXT) w3m dump (earthly.dev)
| kabirgoel wrote:
| Fantastic game! Have you considered using the Bubble Tea [1]
| library?
|
| I recently used Bubble Tea to write a Flappy Bird-like game [2]
| and it was incredibly fun. It splits your app up into a Model
| (state), a View function (that uses the model to return a
| string), and an Update function (that updates the model), like
| Elm. Plus the other Charm libraries are great for styling
| terminal output, spring physics, etc.
|
| [1] https://github.com/charmbracelet/bubbletea [2]
| https://github.com/kbrgl/flapioca
| scoopdewoop wrote:
| I also have been using Go with Tcell recently. Making small games
| is how I have always learned new programming languages.
|
| I am coming off of a couple of years of playing with C to
| understand languages better, and free myself from the complex
| stacks that I use at work. I've been chatting with a highly-
| educated PL friend of mine about my language likes/dislikes, and
| he would always remark on really pragmatic choices Go had made.
|
| I had always dismissed Go, and that has really let me see a
| reddit/HN hivemind I'm susceptible to. It was so easy to think
| "GC? Google? No thanks". After a while I saw a pattern of people
| disparaging Go in favor of Rust, but then using Python/JS for
| their own actual code. It made me feel that maybe the hivemind
| had overlooked the actual use-cases.
|
| I understand that the language had its problems, from sub-par GC
| performance to poor Windows support, to the "no generics" meme.
| But for someone just getting into it now, it has been SEAMLESS.
| VSCode is a first-class dev environment after being configured by
| the single official Go plugin. Modules are awesome, and coming
| from C its so nice to just "go build" and have that _just work_.
|
| I really expect Go to pick up a lot of steam with hobby
| developers soon. For simple games, Go is capable of producing
| cross-compiled static Windows binaries with SDL2 from Linux. That
| kind of dev experience could really win over a lot of C++
| holdouts from the itch.io and HandMade communities that would
| prefer if C++ was just C with classes and types. The GC is so
| fast that it doesn't even cut into a 60fps time budget, and all
| the preallocation tricks from C still work fine... it has
| pointers and arrays like we are used to.
|
| I was shocked to find how much I'd enjoyed Go. If you are
| interested in C/Zig/Odin, I think it is certainly worth checking
| out Go as a tool to play with arrays and structs, a paradigm many
| programmers enjoy. Having high quality libraries in the stdlib
| like JSON (de)serializers and even animated GIF authoring means
| that a lot of the simple code you might write for your own
| amusement won't be subject to the fast bitrot of other
| ecosystems.
| shirogane86x wrote:
| I don't really buy into go (it's not my type of language), but
| I wanted to ask a genuine question: are there many semi-
| mainstream languages that don't have modules that _just work_,
| or an official plugin for VSCode that just works? I've never
| found that to be a "plus", as much as it is the bare minimum.
| and nowadays I don't see that many up and coming languages that
| miss out on it. Admittedly though the cross compilation is nice
| (not enough to win me over, at all, but still very nice. The
| very few times I've needed cross compilation in other languages
| I reached for nix, and that wasn't very pleasant)
| scoopdewoop wrote:
| You tell me, what other language has a drop-in solution that
| provides module management, formatting, integration with the
| debugger, intellisense docs, linting with static analysis
| while I'm typing, and even testing? The plug-in is actually
| made by the Go Team at Google, its not like adding Black and
| Poetry etc. in python, its not even like the moving target
| that is create-react-app or whatever people use now in JS/TS.
| Those are much older languages, but what would you compare it
| to?
|
| I'm not saying Go is the only modern language, its pretty
| retro in some ways, but it has an exceptional tooling story.
| The fact that its mainly based around the official go tool
| helps.
| hedora wrote:
| Rust also has those things. (It also has performance
| profiling, fuzz testing, benchmarking tools, etc, etc., as
| I'm guessing golang does.)
| sk0g wrote:
| Most compiled languages have fractured build ecosystems, and
| may require some tricky invocation orders, external+not-
| included dependencies, or some funky flags depending on your
| compiler version. Or may just not work because you have the
| wrong compiler, missing their preferred build scripting
| runtime, etc.
|
| NPM (packages) frequently go down, doesn't resolve packages,
| or just does something unexpected. Java has the Gradle/Maven
| split, C++ has a few extra common ones - Make/CMake,
| Autotools, Ninja, Meson, etc. Modern C# is the one that's got
| a similar scene to Go from what I've seen.
|
| Go is simple and consistent. It adheres to the Zen of Python,
| particularly "There should be one- and preferably only one
| -obvious way to do it.", better than Python itself does
| (IMO). You check out a repo, you run go build, and 90% of the
| time you have a binary. A 5 line Python script could automate
| this process, good luck doing the same with Java or C++.
| noodleman wrote:
| This is really the selling point of Go for me that makes up
| for it's shortcomings. I've probably lost years off my life
| thanks to gradle.
| [deleted]
| itake wrote:
| > after being configured by the single official Go plugin
|
| Are you using a small or large code base? VSCode falls over at
| my job's monorepo. Goland has much better performance.
| nikki93 wrote:
| Re: perf for hobby gamedev, I basically agree for native
| builds, but lately I've felt like Wasm support seems key for
| hobby gamedev (so you can have more people play your game /
| without downloading it / it works directly on mobile too
| without dealing with app or play store). And Go perf in Wasm
| unfortunately is not so good (I was hitting big GC pauses when
| trying to make a game with Ebiten and large images).
|
| I ended up writing a Go -> C++ compiler. Go's standard library
| parser/typechecker made it very doable. The games I've done
| with it don't use the GC at all but also don't manually manage
| memory -- they use an ECS api which helps.
| https://github.com/nikki93/gx -- the README links to
| development workflow video and complete example game code. I
| get the perf, interop/libs and portability of C/C++ but with
| Go's developer experience (well the build system involves C/C++
| of course but I have something set up there that I now just
| use).
| skrtskrt wrote:
| I've been working professionally in Go for almost a year now
| and I do agree Go is really pragmatic and is largely nice for
| just "getting stuff done".
|
| However there is an absurd amount of nil checking which can be
| easy to miss and not always caught by the common linting tools.
| Once you use Result/Option types and proper enums with pattern
| matching that is expressive and safe, it wears on you that Go
| does not have this.
| PresidentFurman wrote:
| this is dank
| osiemens wrote:
| I learned some basics of Go in much the same way a few years ago.
| An implementation of Andy Sloane's (famous?) donut in a terminal:
| https://github.com/onnos/donut
|
| And playing with funky patterns using braille characters:
| https://github.com/onnos/rotaterm
|
| It's not great quality code but it got me started! It's nice to
| have some immediate output you can play with - tcell is lovely.
| not_a_sw_dork wrote:
| rmahan wrote:
| This is a great idea for learning Go! I've been trying to pick it
| up recently and tried to do a CLI for indexing and searching
| through files. Reading PDFs is such a long hill to climb while
| trying to learn a new language. A game or something with a TUI
| sounds like a much more enjoyable goal.
| pipeline_peak wrote:
| Build Pong in Your Terminal, with Go for some reason
| jalletto wrote:
| I've been trying to learn go by building Pong in my terminal.
| Here is part One where I create a bouncing ball.
| pantulis wrote:
| I remember a pretty similar program that was included in the
| Vic-20 users guide circa 40 years ago. I miss the simplicity of
| learning by coding something that finally ends up like a game!
| adamgordonbell wrote:
| Well now we have a program that says "Hi!" until you press
| escape. For the loneliest among us, that may be enough. But we
| came here to build a game, so we'll need some kind of
| animation.
|
| Love the humor
| boalberto wrote:
| Thanks! Was great fun following along. Noticed a small typo in
| the first code segment, `screen` becomes `s` when calling
| s.Init().
|
| Looking forward to part 2! func main() {
| screen, err := tcell.NewScreen() if err != nil
| { log.Fatalf("%+v", err) } if
| err := s.Init(); err != nil { log.Fatalf("%+v",
| err) } }
| jalletto wrote:
| Thank you! I noticed a few grammar errors as well so I'll be
| sure to update this.
| pbardea wrote:
| I always love projects that build from nothing and go step-by-
| step to build something more complex. Reminds me of one of my
| favorite posts of a similar style building out "Metaballs" with
| different algorithms: http://jamie-wong.com/2014/08/19/metaballs-
| and-marching-squa....
|
| Nice work!
| ryjo wrote:
| Love the other "this is how I learned <language>, too" comments.
| I'll add mine into the mix :) note this was implemented in 2014:
| https://github.com/mrryanjohnston/golang-experiments/tree/ma...
|
| I think videogames are a great way to showcase channels in Go.
| belak wrote:
| The article is great, but the title here has been editorialized a
| bit. I'm not super familiar with HN, so what's the best way to
| get that fixed to match the actual article?
| phnofive wrote:
| Send mail to hn@ycombinator.com :)
|
| Note that this was submitted by the author, who's in the
| thread.
| silisili wrote:
| This was one of my first projects as a kid with Visual Basic. But
| with working paddles and all!
|
| I love Go and use it daily, but I wish we had anything similar to
| VB, even if it's just a helper UI builder. Being able to shape,
| position, and name objects visually, then modify attributes in
| code, is (to me) so much easier than doing it strictly in code.
| Does any such GUI builder exist? I don't necessarily want VB or a
| similar IDE, just a way to design using a GUI and program behind
| it.
| pkaye wrote:
| Lazarus for FreePascal is kind of close but its just for
| Pascal.
| mysterydip wrote:
| I have longed for such a thing as well, having used VB5&6 in my
| late teens to make countless games and utility apps.
| lostgame wrote:
| I know it's Apple-only, but I find Interface Builder in Xcode
| to be an extremely similar and enjoyable experience.
| kodeninja wrote:
| In Tamizh, "pongo" literally means "go" :).
| jalletto wrote:
| This is amazing. Thank you
| csixty4 wrote:
| Who said you need a reason? This is great!
| [deleted]
| spicybright wrote:
| There's not enough projects like this. Do X and Y language where
| X and Y are very specific technologies.
|
| Or maybe I'm just bad at internet searches!
___________________________________________________________________
(page generated 2022-07-26 23:01 UTC)