Questions tagged [language-design]

Questions involving the design and structure of programming languages.

Filter by
Sorted by
Tagged with
1
vote
2answers
151 views

Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface?

Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface (if such implementation is even possible)?
0
votes
1answer
107 views

How to deal with metaclasses in strong-typed language : is it ok to mix classes and metaclasses?

I'm working on a programming language design ans I'm struggling with how I should type the concept of Class. Let me show you some code to illustrate my problem : class MyClass { } function ...
2
votes
4answers
160 views

A language design with variable qualifier

I am planning to design a programming language. One challenge I face with is whether it is a good idea to have const as a variable qualifier instead of a type qualifier. For example in C++: const int ...
7
votes
4answers
576 views

Why does C++ have classes?

The title is deceptive; the question is really "why does C++ have classes and not only structs?" Often, people ask why C++ has structs if they are functionally equivalent to classes. The answer is (...
1
vote
1answer
147 views

Can syntactic `await` always be elided?

(This question isn't a duplicate of Why do we need the async keyword? - it's more of the opposite: I'm not questioning the async keyword - I'm asking if compilers could elide the use of await ...
71
votes
10answers
15k views

Why F#, Rust and Others Use Option Type Instead Of Nullable types like C# 8 Or TypeScript?

AFAIK, Option type will have runtime overhead, while nullable types won't, because Option time is an enum (consuming memory). Why not just mark optional references as optional, then the compiler can ...
0
votes
2answers
140 views

In C++, Why do bitwise operators convert 8 or 16 bit integers to 32 bit?

Is there a logical reason why the integer is upgraded to 32+ bits? I was trying to make an 8bit mask, and found myself a bit disappointed that the upgrade will corrupt my equations. sizeof( quint8(0)...
-4
votes
2answers
87 views

Is it possible to use programming symbols in code? [closed]

A while back I found out there are unicode characters for does not equal ≠ and other characters like less than or equal to ≤ and more than or equal to ≥. I was taking a break from writing any ...
4
votes
1answer
279 views

Design decisions behind access modifiers in C#

I'm currently writing a small language of my own, and have been considering the difference between the C++ style, where the access modifier applies to a block of members, and the C#/Java style, where ...
2
votes
1answer
236 views

Why did C++11 add find_if() instead of overloading find()?

Why did c++11 add a separate find_if() instead of simply overloading the existing find()? Wouldn't overloading the function be sufficient?
0
votes
4answers
162 views

Language design : use equals symbol = both for affectation and comparison, like in MySQL

I'm currently designing a database query language and I came to wonder what should be the best syntax for the comparison operator. Most modern languages use ==, but amongst the database languages ...
40
votes
5answers
6k views

What makes a scripting language “embeddable”?

According to my experience, Wikipedia and prior answers, a scripting language is vague category of languages which are high-level (no manual memory management) and interpreted. Popular examples are ...
-4
votes
1answer
77 views

Is it a good idea to use a Parser Combinator to parse unstructured input?

I'm writing a parser that needs to accept unstructured input. By that I mean it needs to take in a raw signal (text, in this case) and look for significant character sequences while accumulating the ...
28
votes
9answers
9k views

In OOP, isn't the 'protected' keyword required?

Some modern languages (e.g. Swift, Dart) do not support the protected access modifier keyword. Swift is a protocol-oriented language, but I've heard that Dart is a completely object-oriented language. ...
51
votes
7answers
11k views

Is it a bad design for a programming language to allow spaces in identifiers? [closed]

Some (link 1, link 2) programming languages allow spaces in their identifiers (e.g. variables, procedures) but most of them don't and instead programmers usually use camel case, snake case and other ...
12
votes
1answer
686 views

Why was “self” chosen over “this” for the name of the first parameter of python methods?

What was the rationale for choosing the name self instead of this when defining class methods in Python? Yes, of course, you can name it whatever you want - but the widely agreed-upon name for the ...
-3
votes
3answers
174 views

Ideas for a more compact for loop? [closed]

A for loop is quite an important part of a programming language so you don't want to spend a lot of time typing it out every time for prototyping. An example of a quite ugly syntax is: for(int x=0;x&...
0
votes
2answers
145 views

What is the reason python uses range in for loops?

Is there some philosophical reasoning behind why python uses this syntax: for x in range(1,11,3): instead of, for example, the BASIC syntax: for x = 1 to 10 step 3 If Python is supposed to be more ...
0
votes
1answer
121 views

Are parser generators useful for parsing a shell language?

From my understanding, parser generators accept as input some form of context-free grammar description. The context-sensitive features are handled during semantic rather than syntactic analysis (...
1
vote
1answer
133 views

Storage of global variables

In C, global variables are stored with the program code. I.e. the space to hold them is part of the object file (either in the data or bss section), instead of being allocated during execution (to ...
1
vote
1answer
87 views

What is the BNF (or BNF-like) syntax for a specific number of repetitions?

I would like to write something like <byte> ::= <bit>*8 to mean that a <byte> is a sequence of exactly 8 <bit>'s. Is there a way to do this in BNF[1][2] or a widely used ...
14
votes
5answers
2k views

Can every language be categorized as either compiled or interpreted? [duplicate]

As per Wikipedia: A compiled language is a programming language whose implementations are typically compilers (translators that generate machine code from source code). And an interpreted language is ...
3
votes
3answers
321 views

Language design : How to type higher order functions parameters?

I'm trying to design a theoretical programming language and I'm facing a problem with high order functions. The language is strong-typed, so the way to define a standard function is like so : ...
1
vote
2answers
185 views

Is it possible to bootstrap a transpiled language?

There're multiple topics about bootstrapping a compiled language, languages that are compiled into machine code directly; However, I can't find good explanation about bootstrapping a transpiled ...
1
vote
3answers
252 views

Why are Lisp programs a sequence of S-expressions and not a single list?

This is quite basic question that started puzzling me recently while studying Lisp (and derivatives). I have read some Lisp books and web sites and this subject is somewhat obscured by other Lisp ...
1
vote
3answers
234 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
318 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
113 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 ...
4
votes
3answers
291 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
621 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
133 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
707 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
162 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 ...
1
vote
2answers
289 views

Why do malloc and calloc have different signatures?

malloc and calloc have these signatures: void* malloc( size_t size ); void* calloc( size_t num, size_t size ); They do basically the same thing. Both allocate a chunk of memory of the specified size ...
-1
votes
4answers
313 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 ...
3
votes
3answers
690 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
868 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
327 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
147 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
195 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
314 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
342 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
313 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
260 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
575 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
197 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 ...
6
votes
0answers
153 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
138 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
948 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
139 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 ...

1
2 3 4 5
10