flamingo_pinyata@sopuli.xyz to Programmer Humor@programming.dev · 1 day agoYou can pry pattern matching from my cold dead handssopuli.xyzimagemessage-square194fedilinkarrow-up1470
arrow-up1470imageYou can pry pattern matching from my cold dead handssopuli.xyzflamingo_pinyata@sopuli.xyz to Programmer Humor@programming.dev · 1 day agomessage-square194fedilink
minus-squarefruitcantfly@programming.devlinkfedilinkarrow-up3·edit-211 hours ago With Rust you safe 1 char, and gain needing to skip a whole line to see what type something is. Honestly, the Rust way of doing things feels much more natural to me. You can read it as Define a function, with the name getoffmylawn, that takes a Lawn argument named lawn, and returns a bool Whereas the C function is read as Do something with a bool? Could be a variable, could be a function, could be a forward declaration of a function, whatever it is, it has the name getoffmylawn, there’s a (, so all options are still on the table, ok, that’ a function, since it takes a Lawn argument named lawn, that returns a bool
minus-squarecryoistalline@lemmy.mllinkfedilinkarrow-up3·6 hours agotypes in C are pretty weird int *a can be read as *a is a int since dereferencing is a operator on pointers, a is a pointer to int int *a, b is read as *a and b are int so a is a pointer to int and b is a int bool getofmylawn(Lawn lawn) getoffmylawn(Lawn lawn) is a bool since calling is done on functions, getoffmylawn is a function that takes a Lawn and returns a bool And then you have function pointers bool (*foo(int a))(float b) (*foo(int a))(float b) is a bool *foo(int a) is a function from float to bool foo(int a) is a function pointer from float to bool foo is a function that takes a int and returns a function pointer from float to bool really weird in my opinion.
minus-squarefruitcantfly@programming.devlinkfedilinkarrow-up3·4 hours agoC++ is even worse, due to templates and the so-called most vexing parse. Initializing with {} mitigated the latter somewhat, but came with its own set of woes
Honestly, the Rust way of doing things feels much more natural to me.
You can read it as
getoffmylawn,Lawnargument namedlawn,boolWhereas the C function is read as
bool? Could be a variable, could be a function, could be a forward declaration of a function,getoffmylawn,(, so all options are still on the table,Lawnargument namedlawn, that returns abooltypes in C are pretty weird
int *acan be read as*ais a intais a pointer tointint *a, bis read as*aandbareintais a pointer tointandbis aintbool getofmylawn(Lawn lawn)getoffmylawn(Lawn lawn)is aboolgetoffmylawnis a function that takes aLawnand returns aboolAnd then you have function pointers
bool (*foo(int a))(float b)(*foo(int a))(float b)is abool*foo(int a)is a function fromfloattoboolfoo(int a)is a function pointer fromfloattoboolfoois a function that takes aintand returns a function pointer fromfloattoboolreally weird in my opinion.
C++ is even worse, due to templates and the so-called most vexing parse. Initializing with
{}mitigated the latter somewhat, but came with its own set of woes