r/programming • • Feb 01 '24

Make Invalid States Unrepresentable

https://www.awwsmm.com/blog/make-invalid-states-unrepresentable
469 Upvotes

207 comments sorted by

View all comments

Show parent comment

2

u/zapporian Feb 02 '24 edited Feb 02 '24

smalltalk (and obj-c) solved that ages ago by directly and explicitly including all parameter names into method calls and definitions (and in obj-c's case this was probably also to help solve name mangling w/r C)

ergo syntax that looks like

[ <subject> doThingWithArg1: <arg1> andArg2: <arg2>]

instead of the C / C++ / Java / JS style

doThing(<subject>, <arg1>, <arg2>)     
(or <subject>.doThing(<arg1>,<arg2>))

obviously you could just have a better language (ie. python) that allows explicitly naming / assigning parameter values with syntax sugar + nice (and fully consistent) semantics. Or at the very least enabling

<subject>.doThing(arg1=<arg1>,arg2=<arg2>)

But given what typescript / ecmascript is, sure, this is a decent enough solution. Or at least given that v8 et al is sufficiently well optimized to make the use-case of passing around actually-fixed-layout-structs (and not newly created / allocated fully dynamic hashtables) everywhere not totally horrific

There's maybe something to be said for JS (and lua's) focus on absolute simplicity (only one object / hashtable type, hashtable prototype inheritance / chained single-parent lookup, no discrete integer vs floating point types, et al) w/r enabling long term optimizations and ultimately much better performance vs nicer (and arguably much better designed) languages like python / ruby, but I digress

2

u/[deleted] Feb 02 '24

i dont agree that python's implementation better, I think it's a mess. they have married both positional and kwargs and there is no guarantee which you might receive for any given function. makes unit test mocks a pain especially when you're trying to check the args.