News for hackers. Stuff that matters.
Re:Type Checking in JavaScript by mattmanser on Wednesday November 06, 2013 @08:10AM (#6682477)
But have you used statically typed langauges? Unless you've used both you won't be aware of the advantages.

The big one for me is inheriting other people's code bases, in dynamic languages they're a complete and utter nightmare, especially when written by incompetent programmers, which seems to make up a worryingly large number of programmers. Or someone just learning and not aware of conventions.

You just can't assume a method or function actually does what it says it does. Or returns what it says it does. And you can't even see what it's expecting or what things are being passed to it. You have to fine-toothcomb the method, it slows you down massively.

I have worked on a fair few bad code bases now and luckily for me the majority of that's been in static languages. It makes it so much easier.

Some of the other advantages of static typing include:

1. having incredibly good auto code completion

2. never having to remember or look up a method signature

3. to refactor massive chunks of code almost completely fearlessly

4. to fix crap code without any fear of breaking anything else

5. as long as you name your methods well, never having to annotate anything mundane (depending on your audience ofc)

There are also other things like that tend to go hand-in-hand because they're usually explicit, like not worrying about implicit conversion (apart from VB with option explicit off).

I've used both quite a lot over the last 10 odd years professionally programming and I've recently been thinking that I would actually prefer a mix, static typing on boundaries like method entry and new object declartion and dynamic everywhere else. I know little about compiler or language design, so I'm not sure it's even possible. C# kinda gets close with the var keyword, but the various disadvantages of static typing still rear their head quite a lot.

As a slight aside, People on HN always seem to talk as if they only write new programs, not maintain old ones. Am I the weird one for frequently having to pick up code that was written by someone else? Who often had coded themselves into a corner and then made up some excuse as to why they couldn't keep the client anymore?

Re:Type Checking in JavaScript by k__ on Wednesday November 06, 2013 @08:48AM (#6682608)
I had to do some stuff in Java at university, it felt too clunky most of the time. :\

When using libraries, their functions always wanted their arguments to be some strange classes or implement some of their interfaces, which always seemed like big overhead to me.

Stuff like Smalltalk, PHP and JavaScript felt much faster in development speed.

Re:Type Checking in JavaScript by cedias on Wednesday November 06, 2013 @09:34AM (#6682837)
It actually seems like an overhead but in reality it's designed to help you maintain your software easier: Using interfaces makes your software functionnally dependant meaning that it relies on "theorical functions". On the contrary using directly some library makes your software structurally dependant to one's library. This can be a massive issue if the library you're using is not maintained. If you wanted to switch to another one unless you were using a well defined interface that the other library can implement. You would just have to change a few lines of code vs changing a whole lot of calls to one's lib.

IMO, this is one of the major issue of javascript.

Re:Type Checking in JavaScript by Too on Wednesday November 06, 2013 @04:23PM (#6685595)
Java's type system is extreme with its checked exceptions. Try C# instead. I can see the value of checked exceptions for robustness but if you're just prototyping something it drives you nuts.

The specified classes for arguments is a good thing since you dont have to dig through piles of documentation or code review every method you use to understand their behavior.

What do you expect the arguments of the following function to be: 1. A file descriptor, or 2. A path to a file that will be opened by the function?

def print_log(file): ...

One could argue it's bad naming convention but i see shit like this way too often to think it can be solved by conventions. Documenting doesn't work either for the same reason, documentation becomes more boilerplate than specifying types in a type safe language btw.

Contrast this with the C# equivalent

void PrintLog(File file) { ... }

Bang!, You instantly know that the file parameter is a File-object and you can focus your mind on more important things.

Re:Type Checking in JavaScript by ufo on Wednesday November 06, 2013 @09:45AM (#6682894)
Thats because Javas has a clunky type system and bloated libraries full of design patterns. In languages with better support for higher order functions the bit about needing to pass a strange class is much more lightweight.

IMO, real advantages of dynamic typing vs static typing are

* Simplicity. You don't need to learn a complex type system to start coding.

* Flexibility. Dynamic type systems don't stop you from doing useful things ike polymorphism and generics. In a static type system those need to be build in from day 1.

Re:Type Checking in JavaScript by danbruc on Wednesday November 06, 2013 @10:33AM (#6683164)
Completely disagree. Lazy developers not willing to learn a language can not count as argument against statically typed languages. This is a bit like suggesting you should better walk across the country because than you do not need to fuel your car or buy some kind of ticket.

And having to build more advanced type system features on top of a simpler type system is hardly a good thing either - type theory is not trivial and chances that you will get it wrong are large. Even experts in the field make wrong decisions, for example array covariance in Java an C#. And even if you get it right you will usually not enjoy (all) the benefits of compile time type checking and fail only at runtime.

Re:Type Checking in JavaScript by k__ on Wednesday November 06, 2013 @10:39AM (#6683195)
When I had lectures about type-theory in university, it made me even more confident in not using statically typed languages. Those whole contra/covariant problems I read about seemed crazy to me :\

It felt like even the implementers of those type-systems didn't get it right.

Re:Type Checking in JavaScript by mattmanser on Wednesday November 06, 2013 @09:28AM (#6682798)
You actually can't see the advantage of statically typed languages unless you've worked on a non-trivial codebase.

I've never used Smalltalk, but the other two you mention suffer from massive problems when you get to a certain size codebase.

I'm extremely wary of saying this, but I generally think that uni professors/tutors can't program. Basically unless they've written a large open source program or actually worked in the industry for a lot of years, they're probably going to be useless programmers. And even then, there's a good chance they're useless programmers.

That may be a slightly old fashioned view, but most lectures I've seen from unis online tend to completely miss the point of basic concepts (OO being the most common one). And it's rare to meet graduate CS who can actually program anything on their own from scratch. Google's fine, but cut & pasting code you don't understand and changing random stuff as it sounds kinda right, that's not programming, that's a bloody rain dance.

Programming is a skill that needs years of work before you're even vaguely good. And the worst part is you're almost constantly suffering from the Dunning-Kruger effect, thinking you're much, much better than you actually are. I probably still am.

It's one of the reasons we see security holes time and time again, novices don't even realise the problem exists!

For example, I have no idea what to do with crash dump in windbg. I wouldn't even know where to start. Is that a massive knowledge gap? But give me a stack trace of a problem & the source in almost any web language and I'd probably be able to fix it, even if I've never used the programming language before.

Re:Type Checking in JavaScript by k__ on Wednesday November 06, 2013 @10:33AM (#6683167)
Yeah, this is probably true...

But I have to say, my programming prof. was rather fond of Java. Biggest part of the lecture on OOP was about type systems (and I hated it lol).

Most of the stuff I learned about programming, I didn't learn in university, but at work.

But since my experience with Java at university was so bad, I searched for jobs in different languages, like JavaScript.

A few years ago I tried to learn Scala, because it seemed like a better Java to me. But somehow I never got along with it. The type-system seemed logical, but it had so much other stuff around that made starting rather difficult, so I went back to JavaScript.

Re:Type Checking in JavaScript by danbruc on Wednesday November 06, 2013 @08:54AM (#6682640)
...and breaks much more often at runtime.