Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just argument types are useless.

Either all variables shall have types and so static, compile time analysis can be performed.

Or no types at all.



Useless to you maybe.


To anyone.

Types are useful only if they can be checked/verified at compile time.

Types in only arguments cannot be verified by compiler. So type mismatch can be checked only at runtime. So would be this:

   function foo(a:Number) { … }
Is essentially this:

   function foo(a) {
     if( !(a instanceof Number)) throw "Not a number";
     … 
   }
And that rises the question: who and at what moment will handle such errors?


Types are a subset of contracts. Contracts are plenty useful at runtime, as evidenced by the fact that every language that offers design-by-contract (most of which are statically typed) still provides runtime checking facilities. Furthermore, they're usually enabled by default for preconditions, which is what argument types are.

Nobody will handle such errors - contract violations are not supposed to be handled, they're a coding bug. You "handle" them by fixing the caller such that it never violates the contract. The benefit of having a runtime check is that it can detect the error instead of silent wrong behavior potentially followed by state corruption and further bugs. Most of the time, these will fire in automated tests, anyway.


They’re plenty useful if you want to write a library and distribute it (either publicly or within an org) that tells users of the library what they did wrong (other developers) without having to insert type checking boilerplate into every single method.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: