Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [dynamic-typing]

Dynamic Typing is a property of a programming language where type checks are performed mostly at run time.

4
votes
3answers
164 views

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

In statically typed languages or dynamically typed languages that use a type checking system you can guarantee that the input type is the type that you specified in the contract. However, in ...
0
votes
4answers
130 views

Is there a pattern or best practice for returning dynamically typed data?

I have a method that returns the percentage change of a data in a certain period. After calling that method, i need to know if in the current period the data increased, decreased or is the same when ...
1
vote
3answers
200 views

What are some strategies for eliminating switches in polymorphic dynamic code spread across multiple layers?

Context: design with correlated polymorphic classes For example, let's consider the following class definitions for representing messages that we would get from some remote service: class ...
1
vote
2answers
262 views

Best practice regarding interfaces between “typed” and untyped" languages?

Our frontend JavaScript / Vue code makes uses of a number of "internal" REST endpoints, which are implemented in Java using Jersey/jax-rs. We have an "informal" specification that lists the ...
1
vote
2answers
3k views

Web API - strong classes or dynamic?

My web api method should return some structured data about my profile. To do it I created the following POCO classes: public class ProfileInfo { public string FirstName { get; set; } public ...
7
votes
2answers
971 views

Are Dependency Injection Frameworks Useful in Dynamically Typed Languages?

A while ago I was investigating dependency injection frameworks for a project I'm working on in Python (part of a full-time job, moderately large and complex). I found some projects such as ...
0
votes
2answers
333 views

Should I test the aspects that type checking covers?

For example, should I test like this: // it shouldn't even compile since I'm using a static type-checking expect(addTen('string')).toThrowError() when it is already type-checked like this: function ...
2
votes
0answers
237 views

Does using returnTrue() or returnFalse() functions a code-smell?

I was trying to understand how jQuery's cross-browser events work, when I noticed these two functions in the source code: function returnTrue() { return true; } function returnFalse() { ...
2
votes
2answers
182 views

What does “a type system [that] has no hierarchy” mean?

I was reading the Go-lang documents and found under the section of Types that Go has no type hierarchy. What does that mean exactly? Is it like python that types are been checked at run time (...
1
vote
1answer
149 views

Type Conversions in a dynamically typed language - Where should the conversion happen?

I was recently debugging a bit of code where the previous implementation looked something like this: # controller for group/customers def index @customers = current_user.available_customers(param[:...
4
votes
2answers
2k views

Can an interpreted statically typed language be considered type safe?

First let me explain what is my understanding of the terms statically typed language and type safety: Statically typed language: a language that does not allow you to change the type of a variable at ...
4
votes
1answer
796 views

Can dynamic typing and dynamic scoping lead to each other?

By definition, dynamic typing and dynamic scoping have different purposes. But some cases make me wonder if they can lead to each other sometimes. Dynamic typing allows a name i.e. identifier to ...
30
votes
9answers
4k views

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

I've read a related question Are there any design patterns that are unnecessary in dynamic languages like Python? and remembered this quote on Wikiquote.org The wonderful thing about dynamic typing ...
9
votes
6answers
1k views

How is static typing really helpful in bigger projects?

While curiosing on the main page of a scripting programming language's site, I encountered this passage: When a system gets too big to keep in your head, you can add static types. This made me ...
25
votes
2answers
1k views

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

I don't know very well Python. I'm trying to understand more precisely what exact features of dynamic languages (à la Python, Lua, Scheme, Perl, Ruby, ....) are forcing their implementations to be ...
8
votes
2answers
4k views

Why generic interface cannot implement dynamic type?

If it possible: IList <dynamic> = new List <dynamic>; or: class A <T> { A(T){} } class B: A <dynamic> {} . Why it is not possible to do this: class U: IEnumerable <...
42
votes
5answers
4k views

How to avoid typical “dynamic language mistakes”?

I've recently poured a couple of hours into JavaScript because I wanted to benefit from the massive userbase. Doing that I have noticed a pattern that most people attribute to dynamic languages. You ...
7
votes
4answers
896 views

in dynamic language like javascript how do you know what the argument is?

In Java or Scala if I have an argument configuration: Conf, I can look for Conf class/trait/case class and see its construct so I know which arguments to pass. Recently I started dealing with ...
1
vote
3answers
662 views

Do dynamically typed languages, such as Ruby and JavaScript, do any dynamic type checking?

If we look at the definition of "dynamically-typed programming languages" in Wikipedia, it says: Programming languages which include dynamic type-checking but not static type-checking are often ...
4
votes
2answers
380 views

How and when did it happen that, a type is an interface?

I came from a highly functional and procedural background in programming, and never knew that a type is the same as an interface. As in the Design Patterns book by GoF, it says: A type is a name ...
0
votes
5answers
208 views

Confusion about data types, compilers, hardware data representation and static vs dynamic typing [closed]

I am trying to understand static vs dynamic typing, but am really struggling to see how everything fits together. It all starts with data types. As far as I understand, data types are quite abstract ...
2
votes
2answers
1k views

Type checking as opposed to multiple functions?

In statically-typed languages such as Java, code such as the following is common (not much of a realistic example, I know): public String flip(String text) { String result = ""; for (int i = ...
4
votes
1answer
84 views

Methodology for exploring APIs in dynamic languages

As a regular user of Standard ML and, to a lesser extent, Haskell, the following pattern is deeply ingrained into my "instinctive" approach to navigating and learning new APIs: Understand the types. ...
5
votes
2answers
1k views

Does this code follow duck typing?

The principle of duck typing says that you shouldn't care what type of object you have - just whether or not you can do the required action with your object. For this reason the isinstance keyword is ...
6
votes
1answer
421 views

With sufficiently advanced static typing, what are the advantages of dynamic type systems? [closed]

This question appears to be fairly well tread, for example: Do dynamic typed languages deserve all the criticism? What is the supposed productivity gain of dynamic typing? etc. However, most ...
0
votes
2answers
410 views

What is the best type to represent a number in java and why? [closed]

I am developing a dynamically typed, interpreted programming language, which is interpreted by a runtime written in Java. As Java is statically typed, I need to define how the numbers used in the ...
14
votes
2answers
418 views

Is an Optional/Maybe type useful in dynamic languages?

Optional is useful in an obvious way in a statically typed language, but I'm wondering if it's also useful in dynamic languages. Usually there's no compiler telling you, "hey, you used this Optional&...
1
vote
2answers
933 views

What's the benefit of having everything as an object in dynamically typed programming language? [closed]

modern dynamic programming languages like Python, Ruby and Javascript all take the approach of treating everything as an object, what's the benefit of this approach, and what's the curse of it? ...
16
votes
4answers
4k views

Are there programming languages that support both static and dynamic typing? [duplicate]

Being either static or dynamic should be something completely supported in the language. Static vs dynamic shouldn't be something that you have to turn on and off, switching between basically 2 ...
3
votes
2answers
664 views

C# static practices coming from dynamic background

I have been dappling in C# after coming from several years in PHP. I don't find the language particularly difficult, although there are considerably more constructs for me to get used to. My question ...
6
votes
3answers
3k views

Is it possible to have a dynamically typed language without duck typing? [closed]

This question has been asked here, but received poor answers and didn't clarify the issue. I believe it justifies asking it again. I understand that you can have duck typing with either dynamically ...
0
votes
1answer
2k views

Is there a way to prevent variables from changing their type in Python?

It is useful to have the interpreter derive the type of a variable automatically. This on its own is similar to the auto keyword in C++11. However, in Python variables can change their type after ...
3
votes
4answers
6k views

When to not use dynamic in C# [closed]

I'm making a class similar to the following: public class KeyValue { public readonly string key; public readonly object value; } Value could be of any object type as a result of this design. ...
1
vote
1answer
1k views

Static typing vs. dynamic typing [closed]

I'm developing my own programming language in my spare time as a hobby. It's an interpreted language. Currently the syntax for variables is this: %<variable> = <value> Here are some ...
6
votes
7answers
4k views

How can a statically typed language support duck typing?

I understand what dynamic and static type systems are, and what duck typing is. But I don't understand how you can have a static language that supports duck typing. To my understanding only a ...
3
votes
1answer
168 views

A question about static types

How would you statically type the following JavaScript program function c(str) { c = eval(str); return c(str); } I'm not trying to start a flame war but I'm genuinely curious. I've always ...
28
votes
3answers
3k views

Is there a real advantage to dynamic languages? [closed]

First I want to say Java is the only language I ever used, so please excuse my ignorance on this subject. Dynamically typed languages allow you to put any value in any variable. So for example you ...
1
vote
2answers
450 views

is JS a gradually typed language?

I was researching on statically typed and dynamically typed concepts and found out there is another type system called gradually typed. From wikipedia Gradual typing is a type system in which ...
4
votes
0answers
94 views

How significant is the impact of the type system (static/dynamic) on the overall design of programs? [duplicate]

Coming from Java, I've never used a language with dynamic typing. I'm very used to the static-typing way of thinking. My question is, how much does the use of dynamic typing as opposed to static ...
4
votes
3answers
651 views

Classes in OOP , methods and attributes memory internals [closed]

I would assume that instances of the same class would actually share their methods, and just have save different attributes in their namespace. How often do you arbitrary add methods to a single ...
3
votes
3answers
142 views

How do statically typed languages handle test discovery? [closed]

I come from a Python background, so I'm used to pretty automatic test discovery. For example, the py.test library automatically locates any files which begin with test, finds classes whose names start ...
4
votes
1answer
213 views

How are atomic operations are a dynamic language feature?

I was told that atomic operations are a dynamic language feature. I was too afraid to ask in that context what this actually means because I didn't want my coworkers to think I'm stupid. But I ...
3
votes
6answers
2k views

Why is PHP's method of comparing different types bad?

I'm working on designing a new programming language and trying to decide how I will do variable comparisons. Along with many different types of languages, I've used PHP for years and personally had ...
64
votes
14answers
14k views

Is it a bad idea to return different data types from a single function in a dynamically typed language?

My primary language is statically typed (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 ...
20
votes
6answers
3k views

Gradual Typing: “Almost every language with a static type system also has a dynamic type system”

This claim by Aleks Bromfield states: Almost every language with a static type system also has a dynamic type system. Aside from C, I can't think of an exception Is this a valid claim? I ...
3
votes
2answers
4k views

Are all scripting languages dynamically typed? [closed]

Are all scripting languages dynamically typed? I am using TCL. It is a scripting language and it does not enforce or allow type delaration of variables. It is instead a dynamically-typed language ...
5
votes
2answers
608 views

Is using static-typing the solution to domain-driven design and decreasing the number of errors?

We are using PHP (a dynamically-typed language) in our project. However, I have found my colleagues asking questions such as https://stackoverflow.com/questions/20438322/modeling-a-binary-relationship-...
3
votes
5answers
676 views

What are the types of dynamically typed languages arrays?

For example, in JavaScript, I can do such things: var arr = [1, "two", /three/, [4]]; There is no way to do such a thing in C! Except by using a void*, which is not an efficient/safe way. Is this ...
72
votes
5answers
9k views

Is there a correlation between the scale of the project and the strictness of the language?

Explaining the difference between strictness of languages and paradigms to a colleague of mine, I ended up asserting that: Tolerant languages, such as dynamic and interpreted languages, are used best ...
3
votes
0answers
116 views

How to restructure Python frameworks [duplicate]

I just joined a group of five developers (non-professionals) working on a medium sized Python framework (> 50 modules, > 10.000 lines of code). The project has no documentation whatsoever and there ...