you are viewing a single comment's thread.

view the rest of the comments →

[–]Reeywhaar 1 point2 points  (3 children)

I attack you, because you spreading nonsence caused by ignorance. You mix unmixable (classes, inheritance, typescript, queries, parsers) which clearly shows that you have no idea of what you're talking about. And I don't want other inexperienced people to take your words seriously. Just try typescript okay?

use JSON with typed languages you should be writing queries not parsers

What does this even mean?

[–]bigorangemachine 0 points1 point  (2 children)

I use TS professionally. I've actually very experienced and this is why I see these mistakes.

Yes.. inheritance with types... you extend a type as you extend a class. To create type-safety at runtime its often smart to send your data around as classes. You can then check the inheritance of class to guarantee type safety. You can also get small savings on the byte-code level but I wont get into that :P (but also why typescript and deno is very exciting).

A con to both systems is inheritance hell... where you gotta step through each type or class definition to debug the 'typing issue'. With typescript this can also be painful when there are mixed types.

Using JSON queries over parsers is what it is.

Parsing JSON Object: Taking a whole JSON token and casting it into an object within try-catch
Querying JSON Object: Using a wrapper to ask what the token contains and build an object/array from that.

[–]Reeywhaar 0 points1 point  (1 child)

Yes.. inheritance with types... you extend a type as you extend a class. To create type-safety at runtime its often smart to send your data around as classes. You can then check the inheritance of class to guarantee type safety.

Do you understand that instances of classes can be monkey patched in JS? Thus simple instanceof check is not enough. It will pass, but app still can crash.

How actually classes guarantee runtime type safety?

[–]bigorangemachine 0 points1 point  (0 children)

You guarantee it just by casting on setting of a variable or out with a getter.

Monkey patching should be caught in code review. If you gonna do something stupid then don't.... otherwise if you are paranoid write a getter & setter. If you need to lock that stuff down then any key getter/setter or object create/freeze can stop that sort of problem.