8
AleCx04
4y

Any other language: Hey fuckface, you can't name this variable by a single letter, tf is wrong with you? use some descriptive shit.

Golang: lmao fuck u

I really find it interesting how we use short variable names for items in golang. Kinda makes sense when you think of it. Most of these items come up in short methods for which the mental model lets you know and remember what you are doing, they even make sense when going through the std lib in which that shit is all over the place. YET years of going by other languages has made me squint my eyes a bit in frustration every time I see it.
Say for example that a function is implementing io.Writer. What would you call the method parameter? you could argue that writer would be sensible since it has it in the signature, but what about when the io.Writer in itself is a file or a socket or whatever? writer would be funny or strange? nah fuck it just w, it makes sense, but x wouldn't. I find these points to make sense even if i don't like them.

Would, now, this practice be acceptable in C? you are supposed to write the same modular code with C in which you compose large functionality in separated units of code, yet I am sure this practice of single name variables is something that C engineers dislike greatly.

Are go devs just doing this out of blind love for their preference in languages? and how would this work if mfkers add generics to go(I hope not, Go is simple enough to understand in order to extend functionality through the empty interface, but that is a preference of mine as well)

The more I use Go the more I like it to be honest, I think the code looks ugly syntactically, but that is subjective as all hell and based on my constant preference for a language to look like Ruby, which even though it might not be everyone's cup of tea it remains to my eyes as the most beautiful language in existence, again, an obvious personal preference.

Comments
  • 4
    In C, loop index variables are usually single letters, starting with "i" for the outest level. Otherwise, C has a love for cryptic abbreviations (ptr, src, len, fputs), sometimes composed (strcmp, memcpy).

    Oh and by default, Fortran 77 treats variables starting with i-n or I-N as integers, the rest as real (floating type).
  • 3
    I recently started using go, and have noticed just what you're saying a lot. At first I found it quite annoying, and even though it doesn't look that good I actually find it makes the code easy to read and understand. It gives more focus to the actual logic.

    As for generics I got quite upset when I realised go doesn't have anything like it (except for maps perhaps), but I've started to grow fond of the simplicity of Go, and not having generics is probably making it a lot simpler.
  • 1
    By variable names you mean _ right?
  • 1
    @Fast-Nop I was just about to tag you in the comment because I wanted to know about your point of view in this regard(and because you are my favorite C expert). I have seen the use of said mnemonic abbreviations when trying to read c code, I always assumed that such practice was all around established in the c development area. Specially since I have been told that if you don't write proper C code then Linus Torvalds will be under your bed waiting for you at night! Concerning Fortran I honestly had no idea that was a thing! Seems strange from an external point of view, then again I have never written a single line of Fortran code in my life.
  • 1
    @ScriptCoded 100% with you on that man. I am trying to get as good with Go as I can since I want to start moving some of our services at work from PHP into Go. Everything thus far seems rather simple, and I rarely have to deviate from the currently established norms in Go. We'll see how it pans out. I am already building some sort of "framework" which is more like a set of guidelines for structuring a go web project as they would fit best in my organization. I like that I've had pretty much no excuse to deviate from what it is being provided inside of the std lib, seems beautifully complete for most of the things that I am generating, with the exception of the Gorilla set as well as the Cobra CLI packages(external of course) everything else seems beautifully simple and intuitive.
  • 0
    @24th-Dragon you said it man
  • 0
    @yellow-dog see that is a particular exception in that it makes sense to me for it to be that way. You see that and you automatically know that it is for a value that is not being used. At the same time, I am interested in thinking about how it could have been implemented in a different way.
  • 0
    I feel like it's OK if the parameters have little meaning.

    If a function swaps around elements in a list without caring about what the elements are, you don't need descriptive names.

    I hate that Go does this though — the language has no generics (which I see as a huge weakness, personally).

    In Haskell, where there's a LOT of abstraction, using single letters is great. The code is abstract, and so are the variable names.

    But if all your code is specific to one goal, and the language claims that abstraction is an antipattern, it must be descriptive.

    Lack of generics, lack of proper error compound types, some clunky community habits like unclear names and the garbage collector have kind of turned me off Go.

    At work we ran into scaling & maintainability problems with Go, and have since switched to Rust.
  • 0
    Not claiming Go is inherently bad btw... But in my opinion, the design choices do make it's usefulness pretty limited.

    The only place where I still use it is in Google Cloud Functions (similar to AWS Lambda), because writing NodeJS drains my mana too fast.
  • 0
    Don't tell lisp
  • 0
    @SortOfTested examples of lisp having short variable names? I have worked extensively with Clojure and Emacs Lisp, and do not find this to be the case. Now, function names on the other hand.....
  • 0
    @bittersweet thanks for the input man. For the things that I am doing I have not found any limits thus far, mind you that this is only in the form of web development for which the current model in which I am doing this is fairly simple. But after wrapping my head around the use of interfaces I have not seen any real need for generics thus far, maybe I just drank the kool aid already, but will definitely keep an eye on this for when the complexity of the code increases. I wish I could also get into Rust, but the syntax seems severely outputting to me.
  • 1
    @AleCx04 Yeah, and most things are just there, just like you said. Not 20 NPM modules to make a web server...
  • 2
    @ScriptCoded @AleCx04 That there is exactly why I prefer it over NodeJS, Go has just more stuff built in, it's faster for me to go from empty project to deployed service when using Go.

    But one of the reasons why I dislike Go is that you have to either drop some type safety (interface {}), or reimplement the same code multiple times (filter collection of people by name, filter collection of pets by name).

    If the goal of the project is very well defined, like "make a service which polls one API once every minute, chunks the resources, combines items with stuff from another API, and then stores the result in this database", Go is a very valid tool, because you can build so rapidly with it.

    But for projects where the requirements will grow & change iteratively, or some type safety guarantees are needed, I personally wouldn't pick Go.
  • 1
    @bittersweet Yeah, that makes sense. I can't say that I've used it enough to have experienced problems with scaling. But I could sure imagine that happening. However, I'm imagining that if a project has scaling in mind when being started on those problems should be possible to overcome. Can't say though since I don't have the experience.
  • 1
    @ScriptCoded that is specifically one of the things that was killing me from Node. Don't get me wrong, I am one of those that for some reason really enjoys Javascript as a language. But unless you are doing something relatively small in Node, then the idea of having a crazy amount of node modules is something that a developer will have to carry with for the foreseeable future. I have even stopped trying to use Javascript for the frontend for anything unless I am doing it with vanilla JS and even then the ussage is limited.
    I had nothing against server side rendering to begin with and the Go template/html package does literally anything I could want to do. Couple that with some rest endpoints that might be fetched through ajax and we are game.
  • 1
    @AleCx04 Yup, use Node at work and have no issue with it. But the dependencies grow so quick, and if you use Webpack or something you might just get MBs of bundles...
  • 0
    Golang was created primarily by Rob Pike.
    Its design and its style therefore implement his opinions.
    The naming conventions is one of them, as it's documented in the book be co-wrote with Kernighan, The Practice Of Programming.
Add Comment