When use a interface or class in Typescript [duplicate]

At it’s most basic, a class is essentially an object factory (ie. a blueprint of what an object is supposed to look like and then implemented), whereas an interface is a structure used solely for type-checking. While a class may have initialized properties and methods to help create objects, an interface essentially defines the properties … Read more

Is there any way to enforce typing on NSArray, NSMutableArray, etc.?

Nobody’s put this up here yet, so I’ll do it! Tthis is now officially supported in Objective-C. As of Xcode 7, you can use the following syntax: NSArray<MyClass *> *myArray = @[[MyClass new], [MyClass new]]; Note It’s important to note that these are compiler warnings only and you can technically still insert any object into … 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

Are there strongly-typed collections in Objective-C?

In Xcode 7, Apple has introduced ‘Lightweight Generics’ to Objective-C. In Objective-C, they will generate compiler warnings if there is a type mismatch. NSArray<NSString*>* arr = @[@”str”]; NSString* string = [arr objectAtIndex:0]; NSNumber* number = [arr objectAtIndex:0]; // Warning: Incompatible pointer types initializing ‘NSNumber *’ with an expression of type ‘NSString *’ And in Swift … Read more

Is C strongly typed?

“Strongly typed” and “weakly typed” are terms that have no widely agreed-upon technical meaning. Terms that do have a well-defined meaning are Dynamically typed means that types are attached to values at run time, and an attempt to mix values of different types may cause a “run-time type error”. For example, if in Scheme you … Read more

What is the difference between a strongly typed language and a statically typed language?

What is the difference between a strongly typed language and a statically typed language? A statically typed language has a type system that is checked at compile time by the implementation (a compiler or interpreter). The type check rejects some programs, and programs that pass the check usually come with some guarantees; for example, the … Read more

Is Python strongly typed?

Python is strongly, dynamically typed. Strong typing means that the type of a value doesn’t change in unexpected ways. A string containing only digits doesn’t magically become a number, as may happen in Perl. Every change of type requires an explicit conversion. Dynamic typing means that runtime objects (values) have a type, as opposed to … Read more

tech