News for hackers. Stuff that matters.
Re:Google’s Go Style Guide by gbalduzzi on Friday November 18, 2022 @11:12AM (#33656811)
I agree that most types come with a natural variable name.

However, in many cases a more descriptive name is way appropriate. On top of my mind:

- Multiple variables of the same type. How are you supposed to distinguish between req and req2? Compare it to something like "apiReq" and "cdnReq"

- Primitive types, that does not inherently carry a domain value. An integer called "seconds" or "max_offset" has a lot more meaning that one named "num"

Forcing such a notation into the language would make impossibile to represent all these cases

Re:Google’s Go Style Guide by gogogogogogo on Friday November 18, 2022 @02:46PM (#33660958)
The real question from this example is: why are you creating two http requests in the same scope before using them?

I've been writing Go cloud stuff for the better part of a decade and "req" for a request has never been ambiguous because I go ahead and send the request and process the response before sending another one, at which point I can just reassign the variable and let the first one fall out of scope.

Re:Google’s Go Style Guide by gbalduzzi on Monday November 21, 2022 @06:42AM (#33691476)
The request type is just an example, of course, building up from the example in the comment I was replying to.
Re:Google’s Go Style Guide by jawzz on Friday November 18, 2022 @05:56PM (#33663902)
You’re right. Going back to my physics example, all the variables in a physics problem are actually of the same type, float. So you’d need more specific types, but that would be infeasible-the whole point of types in a general purpose language is that they’re general enough for any use case.

If you were just coding physics problems you could have types restricted to the physics domain, that is, physical units. Which it looks like MATLAB does now support: https://www.mathworks.com/help/symbolic/units-of-measurement...

Re:Google’s Go Style Guide by randomswede on Monday November 21, 2022 @04:03AM (#33690430)
Werrrrlllllll... It all depends on what yo umean by "type". In physics problems, I find taht quantities may be measured in "floats", but have the types "mass", "amperage", "distance per second per second" and the like.

In Go, I would probably model this as:

    type mass float64
    type speed float64
    type acceleration float64
That way, they'd all have float64 as the "storage type", but it would be harder to accidentally pass an acceleration when I wanted a mass.
Re:Google’s Go Style Guide by robertlagrant on Monday November 21, 2022 @09:11AM (#33692631)
> Going back to my physics example, all the variables in a physics problem are actually of the same type, float

This is why some people recommend a practice I've forgotten the name of, where they defined a new type that maps to language type. So type Mass could just be a float, but you know better how to treat it.