5 ms·
The Smallest Thing in Go
- unsnap_biceps 2y agoThis is a great primer on iota but the title doesn't make sense to me. I expected talking about an empty struct that uses zero bytes
- js2 2y agoIt's a pun on the English definition of "iota": an infinitesimal amount https://www.merriam-webster.com/dictionary/iota https://www.merriam-webster.com/dictionary/iota
- wgrover 2y agoI'm guessing the title was meant to be a nod toward the meaning of the English word iota, "an extremely small amount".
- akira2501 2y agoAlso the physically smallest letter of the Greek alphabet.
- codegladiator 2y agoI was expecting the smallest binary possible from go
- ramon156 2y agoWhich, mind you, got me interested in go. I remember seeing a docker image of 4mb that ran a pretty well server. Not sure if it's still possible or what article it was.
- InvaderFizz 2y agoStill is. I made a basic http responder last week and it was under 4mb static compiled for a scratch docker container. I didn't even have to resort to compression, just stripped debug symbols.
- kortilla 2y agoA 3.25inch disk (the one that makes the well known save symbol) held 1.44 megabytes. These held entire graphical games and now we’re impressed when we can respond to an HTTP request in a binary that size. Something got lost…
- segfaltnh 2y agoFor a lot of newer compiled languages this comes down to static compilation. These aren't linking to any system libraries beyond the OS fundamentals. That and they have way more debug symbols than Comander Keen, probably.
- kunley 2y agoThere was no crypto stuff during the floppy times, and that's a lot of extra code
- brabel 2y agoThat's impressive. But perhaps this thing is even more impressive: https://redbean.dev/ https://redbean.dev/ It's a single-file webserver that is also a zip file, and that's also a multi-platform executable (that's right, you can run the same file on Windows, Linux, BSDs, MacOS and more). It even includes a Lua interpreter, SQLiteDB, JSON etc. And it's so fast it's unbelievable. Version 2.2 was only 2.2MB , but looks like version 3.0 has grown to 5.5MB, not sure what happened!
- Brian_K_White 2y agoThis looks like plain old enum in plain c. Did I miss something that makes it remarkable?
- akira2501 2y ago> This looks like plain old enum in plain c. It very nearly is. > Did I miss something that makes it remarkable? Yes. The literal 'iota' keyword. There is no equivalent to this in C.
- Brian_K_White 2y agoHow is that remarkable? Does it have some other actual function and this article is only saying how btw it can also be used to make ersatz enums?
- akira2501 2y ago> make ersatz enums? The author is describing 'iota'. You can easily combine this technique with a custom type wrapper which provides the "full enum" if that's actually what you need. In which case this provides a level of capability and convenience above that of C. In practice, it really is quite remarkable, when you first use it to it's fullest extent.
- plorkyeran 2y agoThe basic use of iota is just what C enums do by default.
- akira2501 2y agoThat's one of potentially unlimited use cases. iota composes with just about any static math expression to generate almost any kind of sequence. The most common is obviously conveniently constructing bit vectors; which is possible in C, but not as an automatically composed sequence. This really is a nice feature in practice and certainly not the only type of convenient sequence you can create. A contrived example might be: const ( A rune = 'A' + iota B ) func main() { fmt.Printf("Hello %c", B) } You can, of course, just write it like a C enum if you were so inclined and that willing to go out of your way to show your disinterest in something.
- deleted 2y ago[deleted]
- ydnaclementine 2y agoNot sure where I read it, but I think it's useful to have your 0th iota value be a not valid value, or as your empty/zero value for the enum. Maybe in the planet example you have "Space" or "Nothingness" as your 0 value