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 [static-typing]

The tag has no usage guidance.

3
votes
1answer
51 views

Handling field masks on the statically typed client

Let's say I have a REST API, that has the ability to provide field mask (i.e. the API can return M out of N attributes where M is a subset of N). If a statically typed client (example: one that's ...
13
votes
3answers
400 views

Using static type checking to protect against business errors

I'm big a fan of static type checking. It prevents you from making stupid mistakes like this: // java code Adult a = new Adult(); a.setAge("Roger"); //static type checker would complain a.setName(42)...
3
votes
1answer
607 views

python callback function with arguments bad practice?

I wrote a listener class that executes a programmer specified callback. The msg is provided as a callback argument. I realized that a programmer using the class will need to look at my code to see ...
-1
votes
0answers
69 views

Add and remove interfaces

I was writing code the other day in Java, and was suddenly struck by a desire for the ability to add and remove interfaces from generics. For instance, something like: public <T extends A, IX> ...
0
votes
2answers
310 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 ...
14
votes
3answers
2k views

How do the type systems in functional languages differ from those in OO languages? [duplicate]

I keep reading stories from developers who state that once they are able to get the FP programs written in languages like Haskell, Ocaml, Elm and even Rust, to compile without errors, they are pretty ...
3
votes
3answers
128 views

TDD with predesigned static types

I like working in languages with static types, because I like using types as a tool for designing an API before I start coding it. I also like TDD, because it helps me concentrate on working in small ...
2
votes
2answers
180 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 (...
3
votes
2answers
851 views

Using a superset DTO for a number of methods in a class

Consider a class with a number of methods that are required to return a number of values each. In a strongly typed language such as C#, we can have the effect of returning more that one value from a ...
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 ...
53
votes
10answers
8k views

Why do mainstream strong static OOP languages prevent inheriting primitives?

Why is this OK and mostly expected: abstract type Shape { abstract number Area(); } concrete type Triangle : Shape { concrete number Area() { //... } } ...while this is not OK and ...
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 ...
17
votes
3answers
848 views

Are there alternatives to types for static analysis?

Static typing in a programming language can be helpful for enforcing certain guarantees at compile time- but are types the only tool for this job? Are there other ways of specifying invariants? For ...
7
votes
4answers
883 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
votes
1answer
148 views

Does pure functional programming become agility impediment? [closed]

While I like benefits of strong typing system, there is one thing that worries me the most. I think of strong type system as means of forcing design choices. If a team builds a system unaware of its ...
0
votes
5answers
206 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 ...
0
votes
3answers
350 views

Would it be possible to create a language similar to Ruby/Python with static typing that had the speed/memory usage of a compiled C program? [closed]

One of the main drawbacks of Ruby/Python is performance. I understand that they are interpreted and C is compiled. (And there are things like JRuby which do JIT compilation with Ruby). But they never ...
5
votes
1answer
418 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 ...
9
votes
3answers
540 views

Taking strong, static typing to an extreme? [duplicate]

It is common in strong, static typing to use different types even for variables with simple, primitive types to ease static analysis and indicate intent to the programmer. A color and a point in 3D ...
1
vote
2answers
879 views

Using static classes to define methods for handling POCO class objects

I am pretty new to the OOP paradigm and for this current project of mine, I need to design and develop a web application backend in .NET MVC using C#. A friend of mine told me that the class objects ...
14
votes
2answers
414 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&...
4
votes
4answers
313 views

Styleguide when coding in a static language [duplicate]

I am currently a junior engineer and keen on learning best practices and expanding my experience. My question concerns any static programming language such as Java, C#, C++ etc. When I am writing ...
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
656 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 ...
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
166 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
440 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
647 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 ...
1
vote
3answers
305 views

What are the drawbacks of not declaring a class-method static?

On the 'Interfaces' trail on the Oracle website, we are presented with the following scenario: Imagine a futuristic society where computer-controlled robotic cars transport passengers through ...
0
votes
1answer
812 views

How would I handle a set of differing event classes with differing handler interfaces in a single event processor?

I'm working on an event processor framework for a simple game I'm writing, in which multiple types of events are handled in a loop. Since these events carry distinct pieces of data (i.e. one carries a ...
1
vote
1answer
55 views

Passing around impl-specific tokens in generic algorithms in a static/strong type system

I was interested in solving several unrelated problems using generic graph search techniques, so after some fiddling around I came up with the following design: have each problem implement a generic "...
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 ...
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 ...
19
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 ...
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-...
21
votes
2answers
3k views

Type checking and recursive types (Writing the Y combinator in Haskell/Ocaml)

When explaining the Y combinator in the context of Haskell, it's usually noted that the straight-forward implementation won't type-check in Haskell because of its recursive type. For example, from ...
3
votes
3answers
424 views

Can compilers check whether certain axioms hold for a user defined type?

Suppose the following type is defined (C++ syntax, can be conceptually applied to any statically typed language.) class T { int val; friend bool operator<(const T& lhs, const T& rhs) ...
70
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 ...
1
vote
1answer
266 views

Formal definition of “concepts / type system” for parametric types - Where to start?

I would be interested in formally defining (and consequently demonstrating) a "type system" for, well, a type system. More specifically, I would like to explore the idea of what C++ calls concepts for ...
3
votes
6answers
1k views

In Java, would you sacrifice type safety for a nicer programming interface

When and why would you generally sacrifice typesafety for a nicer programming interface? Let me give you an example: if you had the choice between two event aggregators, which one would you prefer ...
46
votes
1answer
5k views

Why does the .Net world seem to embrace magic strings instead of staticly typed alternatives?

So, I work in .Net. I make open source projects in .Net. One of my biggest problems with it isn't necessariyl with .Net, but with the community and frameworks around it. It seems everywhere that ...
66
votes
4answers
10k views

Is Haskell's type system formally equivalent to Java's? [closed]

I realize some things are easier/harder in one language than the other, but I'm only interested in type-related features that are possible in one and impossible/irrelevant in the other. To make it ...
91
votes
7answers
25k views

What functionality does dynamic typing allow? [closed]

I've been using python for a few days now and I think I understand the difference between dynamic and static typing. What I don't understand is under what circumstances it would be preferred. It is ...
12
votes
5answers
2k views

Are dynamic languages at disadvantage for agile development?

From what I've read agile development often involves refactoring or reverse engineering code into diagrams. Of course there is much more than that, but if we consider the practices that rely on these ...
7
votes
4answers
3k views

Why is Invariance, Covariance and Contravariance necessary in typed languages

Ok not really sure if I'm right. I only recently learned that I needed to have contravariant interface to be able to pass that interface as a parameter in C# and this feature was only added in .NET 4....
5
votes
3answers
434 views

Dynamic typing across the whole technology stack - where to enforce data validity?

Over the past year or two, I've been playing with newer technologies in my side projects. As a web developer, I've gone from the following (and still the following, at work): The 'classic' technology ...