Questions tagged [language-design]

Questions involving the design and structure of programming languages.

1
vote
3answers
170 views

What motivates the design of the root Object type in Java and C#?

In Java and C#, all classes derive from the root class Object (java.lang.Object and System.Object respectively). In both languages/libraries this class comes with a set of methods that are inherited ...
2
votes
2answers
254 views

Why does C# type pattern matching use a different variable scoping behavior than traditional switch blocks?

Traditional switch blocks have one scope, so the following throws a compiler error "A local variable or function named 'message' is already defined in this scope": switch(value) { case 1: ...
1
vote
1answer
92 views

Question about Backus-NaurForm (BNF)

To write the grammar for Whole Numbers (0,1,2...) in BNF, we may write: Number ::⇒ Digit MoreDigits MoreDigits ::⇒ MoreDigits ::⇒ Number Digit ::⇒ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 For a ...
2
votes
3answers
214 views

Why datatypes are marked as thread-safe instead of procedures?

In Rust, Send (or Sync) marker traits are used to indicate whether a value of a type (or a reference to that) can be worked on within threaded context. However, it is an attribute of a function or a ...
1
vote
2answers
131 views

What does the colon before the name mean in this JSON like string?

I encountered this string that looks like JSON syntax but I've never seen a property with a colon before it and not with a backwards greater than or equals sign: Badge { :id=>36, :name=&...
-2
votes
1answer
120 views

Are there languages/syntaxes for representing graphs? [closed]

S-expressions are a well-known way of describing trees in high-level code. Is there something similar for describing graphs? The two closest things I've found are DOT and Ko. Both aren't quite what ...
10
votes
2answers
445 views

How could thread safety be provided by a programming language similar to the way memory safety is provided by Java and C#?

Java and C# provide memory safety by checking array bounds and pointer dereferences. What mechanisms could be implemented into a programming language to prevent the possibility of race conditions and ...
2
votes
2answers
60 views

Definition of intrinsic in language design

I just started looking into programming language design and came across the term intrinsic but could not find any good definition of this anywhere. I hope that someone here can help me with a good ...
0
votes
2answers
144 views

Why does malloc and calloc have different signatures?

malloc and calloc has these signatures: void* malloc( size_t size ); void* calloc( size_t num, size_t size ); They do basically the same thing. Both allocates a chunk of memory of the specified size ...
-1
votes
4answers
308 views

Is simplifying overloading always a good thing?

In comments on In C++ do you need to overload operator== in both directions? Story teller waxes enthusistic about the simplified oveloading provided in c++20 with the <=> operator. That's why ...
2
votes
3answers
429 views

From a language design perspective, is the reference type in C++ mis-designed

Besides the fact that all primitive types of C++ are copy assignable except the reference type, it also doesn't play well with containers or any other parts of the language where copy-assignable ...
2
votes
0answers
180 views

Division by zero Java [closed]

The behavior of Java is explained in this topic. But, is Infinity useful for something? Float: public class DivisionByZeroFloat{ public static void main(String[] args) { System.out....
3
votes
1answer
254 views

Java - What is the “schism” between interfaces and classes that James Gosling talked about? [closed]

Recently, I've stumbled upon an old interview with Dennis Ritchie, Bjarne Stroustrup and James Gosling, published back in 2000. Each of them talked about the language they were most involved with, ...
-2
votes
1answer
127 views

What is the minimum set of operations a language implementation must provide for it to be usable for all applications?

As a fun hobby project, I'm writing a simple bytecode VM and a compiler from a basic high-level language to the said bytecode. (Offtopic: the compiler is inspired by Jack Crenshaw's awesome tutorial -...
-1
votes
1answer
177 views

The Principle of Allowing One Way to accomplish a Task

What is the official name of the principle, in language design, where the language tries to offer one way of accomplishing a particular task (as opposed to have multiple ways of accomplishing the ...
2
votes
1answer
212 views

I'm moving away from using global variables after 7 years, I need help figuring out the basics

Until recently I was a huge fan of global variables because they are simple and allow building solutions to problems quickly. At one point I had to make a slight change to my application: it needed ...
2
votes
2answers
209 views

The dilemma of implementing virtual inheritance

I am working on a program language, and I came to the dilemma whether it should support virtual inheritance or not. As a designer and implementer of the language, including that feature represents ...
9
votes
1answer
187 views

Name of technique for inferring type arguments of a type parameter?

Setup: Let's assume we have a type called Iterator which has a type parameter Element: interface Iterator<Element> {} Then we have an interface Iterable which has one method which will return ...
0
votes
1answer
244 views

Do any programming languages let you use other languages without restriction within them?

This may be a stupid question, and it would certainly take one Hell of a lexer, but do any extant programming languages allow you to do something like: c# (1.2) { // c# code } Perl (5) { # ...
8
votes
2answers
523 views

Only one number type in language design

I am currently learning about compiler construction and language design and I am thinking about what native datatypes I want to support in my language. Now there is a whole lot of languages that make ...
1
vote
1answer
151 views

How do languages ensure 'interior immutability'?

In C#, i can declare an immutable field on a class using readonly. This works for value types, but if its a reference type, there is nothing stopping me calling methods on the object to change its ...
5
votes
0answers
124 views

Why does GHC represent recursion in Haskell with recursive binders instead of a fixpoint operator?

GHC's Core data type represents recursion with recursive binders in the Let constructor; as I understand it, all let expressions in Haskell are effectively let rec expressions. Why does GHC use this ...
2
votes
1answer
131 views

Mark&sweep GC with automatic freeing resources

Note: I use term "resource" in opposition to memory here, resource here is file, socket, etc. Is there a language implementation that uses M&S GC (but not necessarily only that kind ¹) that is ...
5
votes
2answers
668 views

Type-based memory safety without manual memory manage or runtime garbage collection? [closed]

Let's say we wanted a typeful, pure functional programming language, like Haskell or Idris, that is aimed at systems programming without garbage collection and has no runtime (or at least not more ...
0
votes
2answers
132 views

How to validate reference use?

I use "reference" term here like in C++ world, not like in C# (for example). I use non-C++ syntax on purpose -- this is general question, not about this particular implementation. Starting something ...
9
votes
4answers
955 views

Is having a generator language facility such as `yield` a good idea?

PHP, C#, Python and likely a few other languages have a yield keyword that is used to create generator functions. In PHP: http://php.net/manual/en/language.generators.syntax.php In Python: https://...
5
votes
2answers
165 views

How to support inheritance when designing an OO language without classes

I'm designing a programming language for a game, to be used as the main way of interacting with the game, as opposed to using other methods of control, such as the arrow keys or mouse. My plan is to ...
4
votes
1answer
120 views

Tool for validation of new code syntax in existing language

Does a programming language team have any tool to validate their new ideas about new code syntax? As an example, let's assume the Java language team starts developing new feature, which requires new ...
7
votes
8answers
664 views

Is there a compelling reason why columns in SQL are nullable by default?

As a CS student, I've learned a decent number of programming languages over the years, most of which have had some concept of a "nullable" or "optional" type. Note that I'm not talking about null ...
8
votes
2answers
7k views

Why C allows multiple global declarations of the same variable but NOT multiple local declarations?

I noticed that if I declare a global variable multiple times the compiler does not even output a warning. However if I declare a local variable in a function multiple times, for example, the gcc ...
2
votes
1answer
86 views

Why do the column expressions come before the table references in SELECT queries?

It strikes me as weird that the column expressions (everything between SELECT and FROM) in an SQL SELECT statement come before the table references, when the column expressions depend directly on the ...
29
votes
3answers
4k views

Why is there no static keyword in Kotlin?

Kotlin is known primarily as a drop-in replacement for Java, but it gets rid of a well-known Java construct: the static keyword. Instead, that class-level functionality is offered mainly by companion ...
11
votes
8answers
3k views

Unifying programming and database query [closed]

Consider a common tutorial for object-oriented programming languages like C++ or Java: create a simple order processing system with objects representing accounts, orders, items etc (or something more ...
2
votes
1answer
852 views

What is the motivation for Go lang syntax? [closed]

Since the Go lang is getting popular, I started to play with it. I do derive from Java language so when I saw the Go syntax it has been a bit strange to me. sample code from go lang project site: ...
2
votes
2answers
261 views

Is implementing operator overloading with variable arity possible?

Implementing operator overloading for e.g. + (plus) isn't terribly difficult if you know it's a binary operator. One can just parse expression + expression But what if the programmer can choose ...
6
votes
2answers
575 views

OOP without Inheritance [closed]

I'm making a language, and I'm considering disallowing inheritance. To be clear, this means: class A {} //Valid interface B{} //Valid class A2 extends A {} //Invalid class B2 implements B {} //...
3
votes
6answers
223 views

Language Design: skipping occurrences of an identifier instead of accessing enclosing scope

No idea how to write a good title for this question. I'm thinking about introducing an operator in a DSL that makes hidden identifiers (like variables) accessible. Think this.foo in Java or C# to ...
6
votes
3answers
644 views

Why C++ core language is becoming fused with the standard library?

In my understanding, standard library is a whole separate piece of software than a compiler is. In my opinion, they should be kept separate. Advantages of this approach pretty much boil down to "they ...
0
votes
2answers
324 views

Automatically convert mutations in imperative code into functional actions?

I wonder if somebody tried creating a language where you can write mutations in a straightforward imperative style, and the compiler transforms the changes automatically to pure, Redux-style actions. ...
5
votes
0answers
221 views

Different kind of checked exceptions - Guarantee to only throw X

It is a widely held position that checked exceptions as implemented in Java are a bad idea. If you mark a method as throwing, calling code has to either catch the exception, or be marked as throwing, ...
4
votes
3answers
261 views

Why are minor breaking language changes not handled with transpilers?

For any successful programming language, making a breaking change to the language is extremely difficult. This is the case even for those changes where the legacy code could be reliably and ...
75
votes
14answers
16k views

Why is Arithmetic Overflow ignored?

Ever tried to sum up all numbers from 1 to 2,000,000 in your favorite programming language? The result is easy to calculate manually: 2,000,001,000,000, which some 900 times larger than the maximum ...
2
votes
3answers
811 views

In Java, why does Integer.MIN_VALUE == -Integer.MIN_VALUE

Quite simply, I was aghast when I discovered one of my unit tests was failing because -Integer.MIN_VALUE == Integer.MIN_VALUE! Why would the language designers choose this, what is the mathematical ...
1
vote
0answers
222 views

Why are most ReactiveX implementations push-based?

Feel free to correct my history, but as far as I understand it, Rx and the Reactive Manifesto trace their roots back to C# and its Reactive Extensions, which is uses push (callback-based) messaging, ...
2
votes
1answer
601 views

Custom language with mixed markup and Python, parsing in Python

I need a system for creating Python subclasses in a simple manner, and I was thinking of using a (custom) config language similar to json, xml, etc. Here's the initial structure I thought of (one ...
6
votes
3answers
892 views

Why do many languages semantically distinguish “async” functions from “non-async” ones?

I've seen this in C#, Hack, and now Kotlin: await or an equivalent operation can only be performed in special "async" contexts. Return values from these are, to borrow Hack's terminology, "awaitable" ...
0
votes
1answer
170 views

Implement an actor-based concurrent language in ruby?

How would one implement an actor-based concurrent language in ruby? My thought is that only the correct way of creating programs is using actors, but I'm not entirely sure on how this could be done, ...
26
votes
10answers
7k views

Programming language where every function call/block is done in a separate thread? [closed]

I'm currently creating a programming language for fun where the idea is that every function call/new block (if clauses, loops etc) will work in a separate thread. Instead of creating new Threads the ...
-2
votes
2answers
209 views

Categorize a language?

Is it true that one doesn't "implement a programming language"? I was told that in some comment around here several years ago and I read that actually you do "implement a programming language". The ...
6
votes
1answer
588 views

Does C use “$”?

As a general rule, programming languages are designed for use by humans, and thus for entry using a US-QWERTY keyboard. (This makes some number of conceptual skips, myself as proof as I'm doing most ...