Wednesday, February 21, 2024

beginners who like TypeScript

from  3 Lessons from Building a Chrome Extension with TypeScript 

It is striking to me that the "#1 lesson learned" is 

TypeScript feels like Python but JavaScript. It might be a reductive way of describing it, but it feels a lot friendlier to read for a non-techie, self-taught pleb like myself.

The Type interface (even though not as heavily utilized in this project) is amazing. Not struggling with broken code just cause I've inputted a different type that is not supposed to be there.

The streamlined approach to getting what you want, rather than the run around that JS makes you do, helps provide a greater understanding of what is happening from function to function.

I find this such an alien take. For me TS is the opposite of "streamlined" - like I appreciate it for expressing shapes of arbitrary ad hoc JSON formats (though there are other ways of getting that) but am more likely resent the syntax mess it imposes - even by itself JS (and especially with React) is doing more juggling with a pretty small # of charaters ( { }  : =  ?) and so what any given character means in a snippet of code is way more dependent on context, and so harder to read at a glance. And "this only works with a fancy build environment" furthers that lack of a sense of being streamlined. While I know JS in the browser is gonna be some kind of sandbox in a sandbox, having to trust a mapping file to get me from the code I'm inspecting to the code I wrote never feels great. 

I dunno. Sometimes I worry BASIC, Perl and JS broke my brain, and that my feelings that duck typing greases the wheels more than it creates problems and that the speed of a quick interpretation-vs-compiling loop was worth its weight in gold are actually signs of derangement. Maybe Dijkstra was right when he he said

"It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."

(I always assumed he was talking more about line numbers....)

Like I don't MIND strong typing of primitive types, but would prefer the syntax was prettier than `

let foo: string | undefined;

(like from my Java days , I wish the descriptors came before the variable name)

Also the author didn't have to wrestle with some of TypeScript's inheritance ...

Or maybe brains are just different. 

FOLLOWUP:
On a private Slack we got into talking about the pros/cons of types. 

I wrote

Sometimes it feels like "type" as the term for for both primitive types and key/value conglomerations is weird.

like I know if you were thinking in terms of classes it should all be the same thing. But JS is very much not really that class centric..


Ashish wrote 

For me everything is a type. Records/structs have type. Map/Dictionary is a type. Functions are type (takes parameters of certain type and  returns a result of certain type) etc. i recommend Elm or purescript to check out if you like front end stuff.


My response was:

https://elm-lang.org/examples/buttons - this does not look like it would play well with my head.  Seems like a bit too many layers of abstraction from what I think of as UI these days :smile:

It makes me think at CarGurus when we used https://immutable-js.com/ I think the benefits of predictability you get with immutability were way outweighed by the lack of syntactic sugar and sometimes the performance implications.  (not helped by the wayyy academic documentation for it)

I mean that's the whole thing with functional programming and UI - almost by definition almost everything interesting a UI does is a side effect -(most often showing something to the user) - the very opposite of what functional programming wants to be

(Getting more deeply into React, it feels more and more rickety - like it just puts MVC into one big mess of render for the view and controller to mess with the model but not TOO much)

I think of this (1998!) quote:

Menu items are the modern programmer's way -- even that of the Java programmer, who is too pure of heart to use pointers -- of putting an obscene number of unpredictable GOTO statements everywhere in his code.

jhayward@imsa.edu in 1998, via Usenet's "rec.humor.funny"


No comments:

Post a Comment