Skip to main content
41 votes

Are there any design patterns that are possible only in dynamically typed languages like Python?

Short answer: no, because Turing equivalence. Long answer: This guy's being a troll. While it's true that type systems "restrict you to a subset," the stuff outside that subset is, by definition, ...
Mason Wheeler's user avatar
37 votes
Accepted

How to avoid typical "dynamic language mistakes"?

Specifically speaking of JavaScript, you could use TypeScript instead. It offers some of the things you are referring to. Quoting the website: Types enable JavaScript developers to use highly-...
VinArrow's user avatar
  • 484
37 votes

At what point does using a statically typed language gain more benefit than using a dynamically typed language with optional type declaration?

flexible and newbie-friendly, and the strengths of using type are easier to debug and reading code. There's a contradiction here: surely newbies might also want code to be easier to debug, and to ...
pjc50's user avatar
  • 13.7k
28 votes

Are there any design patterns that are possible only in dynamically typed languages like Python?

I'm going to side-step the 'pattern' part because I think it devolves into the definition of what is or isn't a pattern and I've long lost interest in that debate. What I will say is that there are ...
JimmyJames's user avatar
  • 27.7k
23 votes

How is static typing really helpful in bigger projects?

More over, with REPLs it's trivial to test a function for it's return type with different inputs It's not trivial. It's not trivial at all. It's only trivial to do this for trivial functions. For ...
DeadMG's user avatar
  • 36.9k
23 votes
Accepted

What semantic features of Python (and other dynamic languages) contribute to its slowness?

What semantic features of Python (and other dynamic languages) contribute to its slowness? None. Performance of language implementations is a function of money, resources, and PhD theses, not ...
Jörg W Mittag's user avatar
22 votes

Is static typing worth the trade-offs?

There are a lot of strong opinions surrounding the debate but obviously this isn’t actually a matter of opinion, it’s a matter of facts. So we should look at empirical research. And the evidence from ...
21 votes

At what point does using a statically typed language gain more benefit than using a dynamically typed language with optional type declaration?

I'll tell you the exact point where the benefit becomes obvious: the point where you need to make a change to something that's used multiple times throughout your project, that will necessarily impact ...
Mason Wheeler's user avatar
20 votes

How is static typing really helpful in bigger projects?

Think of a project with many programmers, that has changed over the years. You have to maintain this. There's a function getAnswer(v) { return v.answer } What on earth does it do? What's v? Where ...
daven11's user avatar
  • 769
19 votes

How to avoid typical "dynamic language mistakes"?

There are some approaches which can help: Unit testing Write unit tests where possible. Solely relying on manual testing or finding bugs in the wild is hit-and-miss. Use frameworks Rather than ...
Robbie Dee's user avatar
  • 9,805
14 votes

Can an interpreted statically typed language be considered type safe?

Statically typed language: a language that does not allow you to change the type of a variable at run-time. That's not the definition of statically typed. Statically typed means that type checking (...
Jörg W Mittag's user avatar
11 votes
Accepted

Why generic interface cannot implement dynamic type?

This is not allowed, as Chris Burrows (who helped create and implement dynamic) explains: Well, for one thing, it doesn’t actually give you anything that you didn’t already have. The first thing ...
Mason Wheeler's user avatar
10 votes

Are there any design patterns that are possible only in dynamically typed languages like Python?

The quote is correct, but also really disingenuous. Let's break it down to see why: The wonderful thing about dynamic typing is it lets you express anything that is computable. Well, not quite. ...
jk.'s user avatar
  • 10.3k
10 votes

How is static typing really helpful in bigger projects?

You seem to have a few misconceptions about working with large static projects that may be clouding your judgement. Here are some pointers: even if you declare the return type of a function, you ...
Jules's user avatar
  • 17.8k
10 votes

What semantic features of Python (and other dynamic languages) contribute to its slowness?

While Python's current implementation (which lacks a lot of the optimisations performed by other dynamic languages, e.g. modern Javascript implementations and, as you point out, Lua) is a source of ...
Jules's user avatar
  • 17.8k
10 votes

How are dynamic and static typings implemented?

That is generally correct. With static typing, up front optimizations are possible and it is not necessary to represent type information in memory at runtime. With dynamic typing, the relevant type ...
amon's user avatar
  • 135k
9 votes

At what point does using a statically typed language gain more benefit than using a dynamically typed language with optional type declaration?

The point of higher-level languages is not that they can do more. Assembly language can already do everything that a computer can do. Their reason for existing is only ever to assist humans, with ...
Kilian Foth's user avatar
9 votes
Accepted

At what point does using a statically typed language gain more benefit than using a dynamically typed language with optional type declaration?

What can they do that even the addition of type in dynamically typed languages can't do? TL;DR - Static Analysis (including the standard checks the compiler does). As the toolchain / editors get ...
DavidT's user avatar
  • 3,378
8 votes

Type checking as opposed to multiple functions?

It's been a while, but in case anyone is reading this in the FUTURE... The correct answer in 3.5+ is functools.singledispatch. import functools @functools.singledispatch def flip(arg, *args): ...
Adam Michael Wood's user avatar
7 votes
Accepted

Can dynamic typing and dynamic scoping lead to each other?

Dynamic scoping and dynamic typing have two things in common: they have something to do with variables, and they both contain the word “dynamic”. What does “dynamic” mean here? Something is dynamic ...
amon's user avatar
  • 135k
7 votes

Are Dependency Injection Frameworks Useful in Dynamically Typed Languages?

The main benefit of a DI framework is that it moves construction into a different language (xml, json, whatever). This enforces not mixing construction code with behavior code. It's a poor programming ...
candied_orange's user avatar
7 votes
Accepted

Is checking for unexpected types in dynamic languages in an untyped project necessary?

does it make sense to verify the types and write unit tests that unexpected types are dealt with properly Sort of - replace "unit tests" by "automatic tests", and then the answer becomes yes. If ...
Doc Brown's user avatar
  • 210k
7 votes

At what point does using a statically typed language gain more benefit than using a dynamically typed language with optional type declaration?

Restrictions are a Good Thing. Here are examples from C where missing restrictions were later recognized as bug-prone. Where possible, these restrictions were imposed in later versions: Functions ...
Peter - Reinstate Monica's user avatar
6 votes

How is static typing really helpful in bigger projects?

Because static checkers are easier for statically typed languages. At a bare minimum, with no dynamic language features, if it compiles, then at runtime there are no unresolved functions. This is ...
Tim Williscroft's user avatar
6 votes
Accepted

Ahead-of-time compilation to native machine code of dynamically typed languages

Actually, it is easy to compile python to native machine code, in fact the Cython compiler can do it. However, the Cython compiler converts code like: A = B + C Into something like the following C ...
Winston Ewert's user avatar
5 votes
Accepted

Are there any design patterns that are possible only in dynamically typed languages like Python?

First-class types Dynamic typing means that you have first-class types: you can inspect, create and store types at runtime, including the language's own types. It also means that values are typed, ...
coredump's user avatar
  • 5,965
5 votes

Are there any design patterns that are possible only in dynamically typed languages like Python?

The Dynamic Proxy pattern is a shortcut for implementing proxy objects without needing one class per type you need to proxy. class Proxy(object): def __init__(self, obj): self.__target =...
Jules's user avatar
  • 17.8k
5 votes
Accepted

What is the correct way to dynamically declare the type of a variable (in Java)?

You need to declare the variable outside the ifs with type DataSource and assign to it. DataSource ds; if (db_engine == "postgres") { ds = new PGSimpleDataSource(); } else { /* set ds for ...
Winston Ewert's user avatar
4 votes

Dynamically vs Statically typed languages studies

I have found a Static vs. dynamic languages: a literature review, which lists some studies on the subject and gives a nice summary on each study. Here's the executive summary: Of the controlled ...
Mr.WorshipMe's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible