Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
retoor1201223dLike tsoding says, you've people caring about clean code and people that just get shit done :P
Yeah, something i can't figure out what to do in naming is:
- server_run
- run_server
prefixing with server is kinda nice since you'll have all server stuff together in autocomplete. But run_server is more natural but need some remembering.
In dem old days it was very common to name your variables containing the type. Why that's quite clear, some people don't recommend it because of refactoring when the type changes. Ever heard of replace?
I prefer long descriptive names above short names but in the C world it's quite common do small stupid abbreviations. For some reason, the weird abbreviations are very good to remember strncmp, strstr, strchr, fprintf sprintf -
Demolishun3491323dI don't think changing the meaning of a variable is ever a good idea. Unless its a generic function that takes in and spits out the data type you feed it.
I won't do this even in Javascript. -
spongessuck615623dCan you create a builder object that takes the pieces as you go and from which you can compound everything into a result?
-
Ranchonyx1065422dCan't you extend types by just doing something like this?
type With(propname)<T> = T & {
propname: proptype;
}
I'm unfamiliar with rust, but you could chain this together like so:
type BaseUser = {
name: string;
mail: string;
}
type User = WithPermission<BaseUser>;
//-> props of BaseUser & { perms: Permissions };
type SystemUser = WithAdminFlag<User>;
//-> props of User & { isAdmin: boolean };
...and so on.
I like using this pattern which I've taken to calling "type promotion" in typescript.
Defining all possible permutations of, say, a User and creating the "With"-types helps me immensely in naming my variables when using the types in code.
Related Rants
-
vergil32Who, after switching to Linux, started naming their files and folders without spaces?
-
fsociety0013In all honesty, if there was a course on giving variables good, informative and not completely stupid names......
-
Cas97Just finished writing a script with all the classes and variables named after the characters from Sherlock Hol...
in JavaScript I would just call something what it is and then keep changing the data type as I get more data to add to it because you can
in rust because it's not dynamic types but static and everything is a static struct I need to find like 9 different names for all the different intermediary data types and holy shit I don't understand what to name everything and this is annoying me
I never understood why people complained about naming problems. I found it fun. now I hate it.
stats object. cool. well it converts an address to stats. an address has swaps. each swap was done on a mint. so I guess I make a MintStats object? wrong. because that's confusing.
swaps -> swaps divided by the mint they belong in -> stats for each mint swap set -> then you can add all the mint swap set stats to the address stats object
now what the fuck do you call all these
there's also something I called a MintAttitude and it's an enum. these types just keep growing out of trees. fuk. I don't like long names either. I should probably just call it Attitude but call it via mint::Attitude and get the same clarity result with far less redundancy (which I hate, another annoying thing)
swaps -> ??? mint history? -> MintStats -> then I have a "MintData" that has the history and stats wrapped in it -> MintsData that has many mints and their MintData -> then I can convert MintsData into AddressStats but what and I hate this and also I have a Mint object that does something totally different elsewhere. I hate this. data isn't even descriptive but to call something history when it also has stats seems imprecise.
brain spaghetti. classification part of my brain is shit. no historical training / experience either. I just see everything like vague blobs. bah. naming required clear delineations which is hard enough on its own to get used to
rant
naming