What is a sound programming language?

Taken from Dart’s language guide What is soundness? Soundness is about ensuring your program can’t get into certain invalid states. A sound type system means you can never get into a state where an expression evaluates to a value that doesn’t match the expression’s static type. For example, if an expression’s static type is String, … Read more

Angular 14 strictly typed reactive forms – How to type FormGroup model using existing interface

I also ran into this because I always assign my FormGroup later and I was not happy about having to add a ton of boilerplate types on every FormGroup declaration. It felt like I was repeating myself, so what I ended up doing was creating a utility type which has been working well. export type … Read more

Strongly typing props of vue components using composition api and typescript typing system

Troy Kessier’s answer is not entirely accurate. I quote the documentation on definecomponent: Alternatively if your component does not use any option other than setup itself, you can pass the function directly […] So there are not two ways of declaring properties, but rather two ways of declaring a component, and each of them provides … Read more

Can someone tell me what Strong typing and weak typing means and which one is better?

That’ll be the theory answers taken care of, but the practice side seems to have been neglected… Strong-typing means that you can’t use one type of variable where another is expected (or have restrictions to doing so). Weak-typing means you can mix different types. In PHP for example, you can mix numbers and strings and … Read more

Enforce strong type checking in C (type strictness for typedefs)

For “handle” types (opaque pointers), Microsoft uses the trick of declaring structures and then typedef’ing a pointer to the structure: #define DECLARE_HANDLE(name) struct name##__ { int unused; }; \ typedef struct name##__ *name Then instead of typedef void* FOOHANDLE; typedef void* BARHANDLE; They do: DECLARE_HANDLE(FOOHANDLE); DECLARE_HANDLE(BARHANDLE); So now, this works: FOOHANDLE make_foo(); BARHANDLE make_bar(); void … Read more

Difference between Strong vs Static Typing AND Weak vs Dynamic Typing

Static typing vs dynamic typing: Static typing is when your type checking occurs at compile time. You must define a type for your variables inside of your code and any operations you perform on your data would be checked by the compiler. Dynamic typing is when your type checking occurs at runtime. Instead of errors … Read more

Why can’t I inherit from int in C++?

Neil’s comment is pretty accurate. Bjarne mentioned considering and rejecting this exact possibility1: The initializer syntax used to be illegal for built-in types. To allow it, I introduced the notion that built-in types have constructors and destructors. For example: int a(1); // pre-2.1 error, now initializes a to 1 I considered extending this notion to … Read more