Quantcast
Channel: Stack Exchange – Ars Technica
Viewing all articles
Browse latest Browse all 40

In a dynamically typed language, is it a bad idea to return different data types?

$
0
0

Daniel Kaplan asks:

I come from a statically typed language background (Java). In Java, you have to return a single type from every method. For example, you can't have a method that conditionally returns a String or conditionally returns an Integer. But in JavaScript, for example, this is very possible.

In a statically typed language I get why this is a bad idea. If every method returned Object (the common parent all classes inherit from) then you and the compiler have no idea what you're dealing with. You'll have to discover all your mistakes at run time.

Read full article

Comments


Viewing all articles
Browse latest Browse all 40

Trending Articles