Skip to main content

Questions tagged [static-typing]

A statically-typed language is a language (such as Java, C, or C++) where variable types are known at compile time. In most of these languages, types must be expressly indicated by the programmer; in other cases (such as OCaml, Javascript), type inference allows the programmer to not indicate their variable types. Reference: Mozilla

Filter by
Sorted by
Tagged with
10 votes
9 answers
6k views

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

In my understanding, the strengths of not using type are flexible and newbie-friendly, and the strengths of using type are easier to debug and reading code. However now you can use types on ...
Ooker's user avatar
  • 305
0 votes
1 answer
194 views

Are there any general purpose visual programming "languages"? [closed]

Lately I've been surveying the programming language landscape and one of the languages I looked at was Pharo, a modern Smalltalk. Programming using a living system that runs in a virtual machine seems ...
Daniel Arant's user avatar
3 votes
2 answers
272 views

Should a decorated function know about its decorator from a semantic point of view?

In this toy example some_function is... some function that takes a dict as an input and modifies it in place somehow. def some_function(dct: dict): """Do something to the items in ...
Alexander Soare's user avatar
4 votes
3 answers
668 views

Is there a programming language other than Java, C#, and Go which includes null with its static object types?

I was reading the excellent book by Axel Raushmayer, Tackling TypeScript. In this section of Chapter 7, the author makes the interesting claim In many programming languages, null is part of all ...
Ray Toal's user avatar
  • 1,315
1 vote
3 answers
284 views

Are interchangeable types a security vulnerability? Are they good vectors for attack?

Suppose you are given a python API: def onArgumentReceived(x): doWhatever(x) # expects a unicode string I am not a security expert by any stretch of the imagination, however on the face of this, ...
Anon's user avatar
  • 3,613
3 votes
5 answers
457 views

Converting Dynamic Typing To Static Programatically

See: Type inference with duck typing - does this work? Why is it not used? And: General approach for proving decidability/undecidability Hello, I wanted to ask a theoretical question about type system ...
SeriousBusiness100's user avatar
6 votes
5 answers
5k views

Why is C# considered a statically-typed language, although it contains keywords such as `dynamic` and `var`?

C# is considered a statically-typed language. However, it contains keywords such as: var, which infers the type at compile time, and dynamic, which determines the type at runtime. Is this a ...
X Y's user avatar
  • 311
1 vote
1 answer
4k views

Return type specification if a Python function output type, is dependent on the input arguments of that function?

Context Suppose one has a list of algorithms, which each have a multiple run/parameter configurations. Next, one wrote a generic function def get_mdsa_configs(self) -> List[MDSA_config]: that ...
a.t.'s user avatar
  • 225
-2 votes
1 answer
314 views

Domain Driven Design: ElasticSearch and Postgres together

Let me start by saying my knowledge of microservices isn't as strong as it could be. My understanding of DDD is that we'd draw a bounded context over an entity and that would be our service. How does ...
Quesofat's user avatar
3 votes
1 answer
142 views

Designing shared subtype functionality with correct type annotations in Python

To illustrate the problem, I'm defining a PositiveNumber class that is a subclass of a Number class. As Python doesn't support type casting, I'm defining the from_number as a convenience method I can ...
Aresto's user avatar
  • 41
2 votes
3 answers
256 views

Where is the boundary between things which can be statically typechecked, and those which must be typechecked dynamically?

I am brain storming on how to create a type system for a programming language, and what the compiler will do with the typing information. Here is what I have found, followed by the main question, ...
HareSurf's user avatar
  • 2,625
3 votes
2 answers
2k views

How are dynamic and static typings implemented?

As I understand, every programming language is either statically type checked or dynamically type checked (and there are cases where these two approaches are mixed, but for simplicity I won't mention ...
RussoTuristo's user avatar
1 vote
1 answer
1k views

Benefits of Dynamic Mocks over Static Mocks?

I'm not sure if static vs. dynamic mock is the terminology used to describe this comparison, but I got this terminology from types of mocking static vs dynamic and Hand-rolled mocks made easy. To ...
Mario Ishac's user avatar
0 votes
1 answer
116 views

Is dynamically hiding specific parts of the input data passed to a function pythonic?

I have a design question regarding "dynamic information hiding" vs static typing. I have for the following python code class RuleInput: attr1 = ... atrr2 = ... ... def ...
steve's user avatar
  • 19
6 votes
3 answers
537 views

Where to convert primitive types in meaningful types in Clean Architecture / Onion Architecture

The book "Implementing Domain Driven Design" (page 361) suggests to use special types to distinguish several kinds of IDs, e. g. using BookId(1) instead of just 1 of type Int or Long. In my Clean ...
deamon's user avatar
  • 876
1 vote
0 answers
127 views

What to do about compilation errors if ignoring them makes the app run fine?

Updating the libraries in my Angular 8/Electron app produced compilations errors eg, in Electron's menu.ts file, Also, a few of the project external libraries contain @ts-ignore lines, suppressing ...
schrödingcöder's user avatar
1 vote
1 answer
912 views

When is it a good idea to include explicit type declarations in Kotlin?

In Kotlin, specifying the return types of functions and the types of variables is usually optional but can be optionally included. I've encountered a few benefits of including them: It sometimes ...
fluidj's user avatar
  • 147
3 votes
1 answer
147 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 ...
labheshr's user avatar
  • 131
13 votes
3 answers
475 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)...
J-bob's user avatar
  • 299
3 votes
1 answer
2k 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 ...
ta32's user avatar
  • 47
0 votes
2 answers
882 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 ...
Christopher Regner's user avatar
19 votes
3 answers
3k 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 ...
vfclists's user avatar
  • 299
2 votes
3 answers
170 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 ...
Periata Breatta's user avatar
3 votes
2 answers
327 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 (...
ThunderWiring's user avatar
3 votes
2 answers
2k 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 ...
Sнаđошƒаӽ's user avatar
6 votes
2 answers
6k 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 ...
user247763's user avatar
53 votes
10 answers
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 ...
Den's user avatar
  • 4,847
9 votes
6 answers
2k 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 ...
user6245072's user avatar
19 votes
3 answers
1k 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 ...
Max Heiber's user avatar
7 votes
4 answers
1k 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 ...
Jas's user avatar
  • 507
-1 votes
1 answer
166 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 ...
sevo's user avatar
  • 621
0 votes
5 answers
234 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 ...
Lord Cat's user avatar
  • 139
0 votes
3 answers
491 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 ...
Brian Armstrong's user avatar
6 votes
1 answer
560 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 ...
charl's user avatar
  • 177
9 votes
3 answers
666 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 ...
Josh's user avatar
  • 201
1 vote
2 answers
1k 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 ...
labyrinth's user avatar
  • 141
14 votes
3 answers
705 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&...
Daniel Kaplan's user avatar
3 votes
4 answers
326 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 ...
Adrien Cadet's user avatar
16 votes
4 answers
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 ...
vlad-ardelean's user avatar
3 votes
2 answers
856 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 ...
Flosculus's user avatar
  • 183
1 vote
1 answer
2k 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 ...
Francis's user avatar
  • 29
7 votes
7 answers
5k 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 ...
Aviv Cohn's user avatar
  • 21.4k
3 votes
1 answer
178 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 ...
user avatar
32 votes
3 answers
5k 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 ...
Aviv Cohn's user avatar
  • 21.4k
1 vote
2 answers
664 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 ...
Roshan.Ind's user avatar
4 votes
0 answers
100 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 ...
Aviv Cohn's user avatar
  • 21.4k
4 votes
3 answers
756 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 ...
Dim's user avatar
  • 149
3 votes
3 answers
167 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 ...
Alex Gaynor's user avatar
1 vote
3 answers
334 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 ...
John Gowers's user avatar
0 votes
1 answer
1k 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 ...
nanofarad's user avatar
  • 451