Questions tagged [language-design]
Questions involving the design and structure of programming languages.
476
questions
-4
votes
1
answer
87
views
Is named return good feature for programming language [closed]
I design my own general purpose hobby language right now. I want to implement named returns feature.
Here is example of JS code, which looks like named return.
const sumAndMinus = (num1, num2) => {
...
8
votes
3
answers
3k
views
What is a real-world use case of using a Chomsky Type-I (context-sensitive) grammar
I have been having some fun lately exploring the development of language parsers in the context of how they fit into the Chomsky Hierarchy.
What is a good real-world (ie not theoretical) example of a ...
2
votes
4
answers
295
views
What are the trade-offs between garbage collection and Automatic Reference Counting?
By "Automatic Reference Counting", I am refering to the specific feature of the Clang compiler. By "Garbage Collection", I am refering to Tracing Garbage Collection, not to "...
8
votes
5
answers
556
views
In retrospect, has it been a good idea to use three-valued logic for SQL NULL comparisons?
In SQL, NULL means "unknown value". Thus, every comparison with NULL yields NULL (unknown) rather than TRUE or FALSE.
From a conceptional point of view, this three-valued logic makes sense. From a ...
0
votes
3
answers
3k
views
SQL: Empty value list for the IN predicate (literals, not subqueries)
Recently, while writing some Spring/JPA code, I stumbled on an issue I tend to face with from time to time: I passed an empty collection to a repository method that generates an IN expression for the ...
1
vote
3
answers
345
views
Why does HTML collapse whitespace?
I've been trying to better understand (at least at a high level) why the early versions of HTML were designed the way they were. Most of the decisions make sense; I can deduce (at least at a high ...
78
votes
6
answers
15k
views
Why does the type go after the variable name in modern programming languages?
Why is it that in nearly all modern programming languages (Go, Rust, Kotlin, Swift, Scala, Nim, even Python last version) types always come after the variable name in the variable declaration, and not ...
9
votes
1
answer
477
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, ...
44
votes
5
answers
18k
views
When does it make sense to compile my own language to C code first?
When designing an own programming language, when does it make sense to write a converter that takes the source code and converts it to C or C++ code so that I can use an existing compiler like gcc to ...
0
votes
2
answers
379
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) {
# ...
3
votes
1
answer
107
views
Choosing the design of a scientific DSL: purely or impurely functional?
My aim is to create a language specific to the scientific field (which would be used mainly in the field of machine learning and physics) which would be based on the functional paradigm, a paradigm ...
34
votes
3
answers
6k
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 ...
5
votes
5
answers
940
views
Which programming languages provide a Schwartzian transform like interface for sorting
Introduction
The Schwartzian transform -- also known as map-sort-map or decorate-sort-undecorate (DSU) --, attributed to Randal Schwartz of the Perl community, sorts elements of a list or array by a ...
37
votes
7
answers
9k
views
Why do programming languages allow shadowing/hiding of variables and functions?
Many of the most popular programming languges (such as C++, Java, Python etc.) have the concept of hiding / shadowing of variables or functions. When I've encountered hiding or shadowing they have ...
7
votes
6
answers
2k
views
What is the purpose of a delegate type variable?
In C#, we have delegates, which are essentially variables (holders) for methods that follow a signature. So, I could write
delegate void MyDelegate(int num);
MyDelegate myMethodHolder;
Now, ...
38
votes
9
answers
6k
views
Why do C# and Java use reference equality as the default for '=='?
I've been pondering for a while why Java and C# (and I'm sure other languages) default to reference equality for ==.
In the programming I do (which certainly is only a small subset of programming ...
5
votes
3
answers
2k
views
Variable declaration versus assignment syntax
Working on a statically typed language with type inference and streamlined syntax, and need to make final decision about syntax for variable declaration versus assignment. Specifically I'm trying to ...
68
votes
10
answers
19k
views
Syntax Design - Why use parentheses when no arguments are passed?
In many languages, the syntax function_name(arg1, arg2, ...) is used to call a function. When we want to call the function without any arguments, we must do function_name().
I find it strange that a ...
12
votes
3
answers
2k
views
Are first-class continuations useful in modern object-oriented programming languages?
Continuations are extremely useful in functional programming languages (e.g. the Cont monad in Haskell) because they allow a simple and regular notation for imperative-style code. They're also useful ...
55
votes
8
answers
20k
views
Why design a modern language without an exception-handling mechanism?
Many modern languages provide rich exception handling features, but Apple's Swift programming language does not provide an exception handling mechanism.
Steeped in exceptions as I am, I'm having ...
3
votes
3
answers
313
views
Is there any performance hit associated by the definition of a static constructor or due to availability of it?
This question is mostly related to the way language implementer do implements static class initalization (pretty specialized question). It is for curiosity and also to potentially improve my code to ...
89
votes
11
answers
18k
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 ...
2
votes
1
answer
162
views
Is there a language implemented as a neuron network?
Does there exist some language whose execution model is implemented as a neuron network, or maybe as some other type of a network/grid (e.g. network of finite automata)? That is, specifically, without ...
0
votes
2
answers
508
views
How can Python, a language that supports Object Oriented Programming, be implemented in C, which is not an Object Oriented Programming language?
To my understanding, C does not have the concept of objects, then how can Python be implemented in C to support something that C can not? How is the concept of "Object" modeled in C? What is ...
4
votes
4
answers
337
views
Is there a cancel after certain amount of time try catch type of block?
I'm going through a beginner programming learning guides and the teacher brings up the try catch block paradigm.
The code you put in the try block is run and if an error happens the code in the catch ...
2
votes
1
answer
81
views
Hot reloading anonymous functions in a custom scripting language
I am implementing anonymous functions (lambdas) in a scripting language that supports hot reloading. The language currently supports passing user defined functions (pointers) to plugin functions which ...
42
votes
5
answers
9k
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 ...
8
votes
1
answer
348
views
What type of syntax notation is this?
SQL Server documentation uses this notation, which is very easy to understand and consume. Is this a BNF Syntax Diagram? Or is this a different type of notation?
Source: SQL server documentation page ...
2
votes
4
answers
2k
views
Why doesn't System.String include a constructor taking an IEnumerable<char>?
Why doesn't System.String include a constructor capable of taking a IEnumerable<char>?
The expected behavior would be:
var foo = "hello";
var bar = new string(foo.Select(x => x));
Actual ...
86
votes
11
answers
12k
views
Did the developers of Java consciously abandon RAII?
As a long-time C# programmer, I have recently come to learn more about the advantages of Resource Acquisition Is Initialization (RAII). In particular, I have discovered that the C# idiom:
using (var ...
14
votes
2
answers
3k
views
Why is the 'out' keyword used in two seemingly disparate contexts?
In C#, the out keyword can be used in two different ways.
As a parameter modifier in which an argument is passed by reference
class OutExample
{
static void Method(out int i)
{
i = ...
36
votes
6
answers
15k
views
Why is studying a Lisp interpreter in lisp so important?
I have seen many CS curriculums and learning suggestions for new programmers that call for the aspiring programmer to study a Lisp interpreter that is specifically written in Lisp. All these sites ...
-1
votes
1
answer
66
views
Appropriate base type for simply typed lambda calculus
Given the following hypothetical programming language:
Intended for practical programming
A simply typed lambda calculus (STLC)
All objects are functions, based on Church encodings
I am aware that ...
21
votes
14
answers
2k
views
Should data structures be integrated into the language (as in Python) or be provided in the standard library (as in Java)?
In Python, and most likely many other programming languages, common data structures can be found as an integrated part of the core language with their own dedicated syntax. If we put LISP's integrated ...
11
votes
2
answers
15k
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 ...
54
votes
2
answers
20k
views
Why is 'void' not allowed as a generic type in C#
What were the design decisions that argued in favour of void not being constructable and not being allowed as a generic type? After all it is just a special empty struct and would have avoided the ...
9
votes
6
answers
983
views
Do any programming languages use types as values? Would there be any point?
The standard way that types are handled in programming languages that have such a concept, is that they are:
removed entirely at compile time and are just used to determine memory layout, function ...
4
votes
5
answers
2k
views
Why don't languages like C have NAND operators?
I know that some golfing languages like APL have a dedicated NAND operator, but I'm thinking about languages like C, C++, Java, Rust, Go, Swift, Kotlin, even instruction sets, etc. since these are the ...
60
votes
9
answers
7k
views
Why do "checked exceptions", i.e., "value-or-error return values", work well in Rust and Go but not in Java?
Java has "checked exceptions", which force the caller of the method to either handle an exception or to rethrow it, e.g.
// requires ParseException to be handled or rethrown
int i = ...
12
votes
1
answer
8k
views
static globals and anonymous namespaces in C++
Why did C++ make any distinction between static globals (internal linkage) and symbols in an unnamed namespace (external linkage, but no way to refer to it from outside anyway), when introducing the ...
10
votes
2
answers
3k
views
Why can't an ES2015 WeakMap have primitive keys?
There are six primitive data types in JavaScript:
Boolean, Number, String, Symbol, undefined, null
A WeakMap can't have primitive data types as keys. And a WeakSet can't have primitive values.
Why ...
-1
votes
3
answers
394
views
Why are constants declared with `let`?
A few weeks ago, I went on Udemy course on Swift, the instructor mentioned that constants are called let in Swift because it's standard in OOP (JavaScript uses it for example).
I know this may seem ...
98
votes
12
answers
34k
views
Should I use a parser generator or should I roll my own custom lexer and parser code?
What specific advantages and disadvantages of each way to working on a programming language grammar?
Why/When should I roll my own? Why/When should I use a generator?
28
votes
2
answers
19k
views
Why are packages and modules separate concepts in Java 9?
Java 9 will have modules in addition to packages.
Usually languages have one or the other.
And most programmers perceive two terms as synonyms.
Modules are built on top of packages, treating them as ...
-1
votes
1
answer
169
views
What advantage is gained by continuing to not provide an UPSERT statement in T-SQL (or any given major SQL dialect)?
This question is asking about a generally applicable engineering principle. It is using T-SQL as a specific example, but the question is about the engineering principles behind major SQL dialects in ...
19
votes
10
answers
8k
views
Function overloading? Yes or no [closed]
I'm developing a statically- and strongly-typed, compiled language, and I'm revisiting the idea of whether to include function overloading as a language feature. I realized that I'm a little bit ...
62
votes
6
answers
27k
views
Why was C# made with "new" and "virtual+override" keywords unlike Java?
In Java there are no virtual, new, override keywords for method definition. So the working of a method is easy to understand. Cause if DerivedClass extends BaseClass and has a method with same name ...
3
votes
3
answers
11k
views
What are the advantages of pass by value?
I always thought pass by value is a legacy from the early languages, because the designers had never seen anything else. But after seeing the brand new languages like Go adapting the same principle ...
5
votes
5
answers
473
views
Reasons to use (and not to use) a repeated delimiter to escape that delimiter?
For the designer of a language syntax, what are some reasons to choose a repeated delimiter to escape that delimiter, instead of having a separate escape character to escape that delimiter. A common ...
5
votes
1
answer
207
views
Real-world scenarios for protected inheritance
C++ supports protected inheritance: A class can derive from a base class B in a way that the "outside" world doesn't see that class "as a B" but the class itself and it's derived ...