6 ms·
Probably the single worst conclusion someone can arrive at regarding typing.
by mahmud 13y ago
Probably the single worst conclusion someone can arrive at regarding typing.
- harrytuttle 13y agoRather than slate me, some constructive discussion would be nice. I'll go from my side: 1. Static type compiler verification saves tonnes of problems. Try managing a 2MLOC dynamically typed solution and you'll get what I mean. 2. Static typed languages are way easier to refactor as more metadata is available to the tooling. 3. Static typed code is easier to test. The type contract is available over the boundary between the implementation and the test cases. 4. Defined interfaces without leaky abstractions are easier to produce when you have static types. 5. Static types allow the compiler to infer more information about how to compiler your code resulting in faster, more efficient code and lower memory usage plus you don't have to compile an instance of a function with every possible type consideration at runtime. 6. Statically typed data serialises more reliably i.e. goes over the wire easier without behemoth contracts and parsers at each end. 7. Statically typed languages tend to have better numeric accuracy as differences between decimal, floats and integers are always deterministic and there are defined casts and conversions between each during operations. I could go on...
- mahmud 13y agoYour heart is in the right place, but you're stuck with a bad example still. C is hardly a good representative for an statically typed language. Read Luca Cardelli's "Typeful Programming"[1] to get an overview of what typed programming is all about, and see for yourself how brain-dead C and C++ are in comparison. After that go to Benjamin Pierce's canon, "Types and Programming Languages". [1]http://www.daimi.au.dk/~madst/tool/papers/typeful.pdf http://www.daimi.au.dk/~madst/tool/papers/typeful.pdf
- nly 13y agoI don't think it's fair to call C++s type system 'brain-dead' when it was developed pragmatically to be largely source compatible with C. It introduced stronger array types, eliminated Cs automatic void* -> T* conversion and, most importantly, put higher-order functions and types on the table. It might be a warty syntactical abomination, but it can still hold its own against some of the languages of type extremism.
- marshray 13y agoSo what would you consider to be the "good representatives for an statically typed language"?
- mahmud 13y agoA language with a statically enforced type system? Anything in the ML family for starters, but more popularly, Java, C#, the Pascal family, etc.
- lucian1900 13y ago5 is not entirely correct. 6 is not true, serialisation in dynamic languages is correctly done with type definitions. 7 is not true at all, mainstream statically typed languages (like C) much more commonly overflow silently. Look at Python, there's no way to lose precision through arithmetic, as types get promoted on overflow correctly. In general, C's type system is so weak as to be both useless and a hindrance.
- harrytuttle 13y ago5 is true for the cases where it results in static compiled output which is equivalent of say C's output. 6 you're adding metadata with type definitions. Enough metadata is present in entirely statically typed languages to not do this. 7. How do you know if 1.000000000000000000001 is decimal or float? It's weak in some places but strong in others. Knowing when to use each case effectively is the art.
- lucian1900 13y ago6. It's still necessary (or at least a good idea) to write serialisation models for most statically typed languages as well. the difference is minor 7. It's a float, unless you made it a Decimal explicitly. Arguably that's the wrong default, but almost no languages default to arbitrary precision/size everything. No, C's type system is totally unsound. It fails to catch very bad errors (pointer-related issues, null-related issues, etc.) and is perfectly happy to implicitly cast left and right. It's little more than a hindrance.
- seanmcdirmid 13y agoC has very simple types and allows for untyped operations very easily. Say you cast some ptr of type void* to Foo*: at least in Python you would get a dynamic type error if the cast was incorrect; in C you are lucky if your program immediately crashes. C has some static type safety, and virtually no run-time type safety. Java on the other hand, has a lot of static type safety, is completely memory safe (barring bugs in the implementation), and checks all coercions dynamically. Python has what Java has dynamically, and nothing statically, but it is still 10 times better than what C has!
- harrytuttle 13y agoThat's what we have valgrind, test cases and decent software engineers for. Java don't forget suffers as do other languages from lots of nasty things related to types including invalid casts, null reference exceptions etc. When these go phut in production, you're usually in the same situation.
- pkinsky 13y agoJava is not a good example of a statically typed language. Null pointer exceptions just don't happen in idiomatic Scala. For example, let's say I have 3 functions a,b and c, each with signature Int => Option[Int]. Any one of these can return Some[Int] or None. Options, like all collections, can be chained together as such: for { x <- a(1) y <- b(x) z <- c(y) } yield z this expression is of type Option[Int], and will never throw a null pointer exception. (Futures can be chained together with identical syntax)
- seanmcdirmid 13y ago> Null pointer exceptions just don't happen in idiomatic Scala. But match exceptions do. Anyways, if I had to choose between unsound static type checking and sound dynamic type checking, I would definitely choose the latter.
- happy_dino 13y ago
- michaelwww 13y agoMy worst nightmare would be managing a 2MLOC inherited from a programmer who used void * as a convenience so it's a little surprising to hear this.
- harrytuttle 13y agovoid* is used rarely in practice, apart from perhaps kernel mode or language VM's. I have a 150kloc program in front of me which doesn't have a single void*.
- michaelwww 13y agoGreat. That makes more sense. I must have misunderstood what you were saying.
- harrytuttle 13y agoYes we're not gluttons for punishment believe me :)
- nly 13y agovoid* is used in practically every C library that offers a callback facility.
- harrytuttle 13y agoAlmost... You have a typed pointer to a function but that's not a void pointer and the "New C Standard" 6.3.2.3 states that you can't cast a function pointer to a void*.
- ygra 13y agoNot for function pointers; for passing data to callbacks that can be any type.
- 13y ago