Questions involving the design and structure of programming languages.

learn more… | top users | synonyms

0
votes
1answer
62 views

A secondary “type system” for references?

I'm designing a language and was wondering how to incorporate C++-like references with regards to their place in the type system. I think they're useful for operations like indexing and dereferencing ...
3
votes
3answers
3k views

Banning zero-argument functions — what problems could it cause in a hypothetical language?

I'm creating a programming language as a hobby, but I encountered a problem with designing its syntax. The problem is the conflict between the syntax for defining zero-argument functions and the ...
11
votes
2answers
886 views

Type system for performance

Do (static) type systems exist which attempt to formalize the performance characteristics of programs? I cannot find seem to find such attempts. Since type systems are (one of) the most powerful ...
1
vote
2answers
112 views

Language/Programming term for paired delimiters [closed]

Can someone help me find the language and/or programming term for delimiters (?) that must be paired? Quotes, parenthesis, angle-brackets, square-brackets, etc. are often used to symbolize these ...
0
votes
2answers
165 views

Why can't I use an operator like plus sign to concatenate strings? [closed]

Why in Objective-C we should be typing explicit references to methods like stringByAppendingString to concatenate strings, when in some other languages we can use operators for that? For example, ...
9
votes
1answer
302 views

Why it is not possible to overload compound assignment operator in C#?

The title is be misleading, so please read entire question :-). By "compound assignment operator" I have in mind a construct like this op=, for example +=. Pure assignment operator (=) does not ...
0
votes
1answer
89 views

Is Objective-C the only language with infix arguments?

One of the things I like about Objective-C is the use of infix arguments when calling a method. [myDictionary setObject:myObject forKey:@"key"]; where the method name is setObject:forKey:. Does any ...
3
votes
3answers
111 views

Would implementing a “Throwable Event System” be abusive?

I have been thinking for a couple years now about using Throwable events and implementing a sort of event system that uses throw to dispatch an event, or let a different method handle it with throws. ...
0
votes
1answer
59 views

Would it be good to have a readonly modifier for method level variables?

In C# you can use the readonly modifier for a class level field to indicate (to comipler and other DEVS) that once set it cannot be changed. I'd quite like for the ability to mark a variable declared ...
2
votes
3answers
300 views

Does a Completely Full-Featured Intermediate Language Exist?

Often when translating between languages (whether with program translation or compiling) it's a one-way, destructive translation. The functionality of the "port" isn't lost, but some of the intent ...
3
votes
1answer
278 views

In C++, why does the main function use 'char *argv[]'?

I was wondering why C++ uses the following function prototype for the main() function: int main(int argc, char *argv[]); instead of something like: int main(std::vector<std::string> argv); ...
1
vote
2answers
68 views

How to implement rounding in an all-purpose stack language using different types?

Disclaimer: If you are not terribly interested in numerics and mathematical processes, this is most likely nothing for you. I am currently a bit stuck in a development process of a private project I ...
27
votes
4answers
3k views

Why is .compareTo() in an interface while .equals() is in a class in Java?

I want to know why the .compareTo() is in the Comparable interface while a method like .equals is in the Object class. To me, it seems arbitrary why a method like .compareTo() is not in the Object ...
4
votes
2answers
120 views

What do you get when you cross a multi-precision integer with a floating-point number?

I'm working on adding multi-precision integers to the suite of numeric types in my APL interpreter, but I'm not sure what to do about the odd type-combinations that now arise. I now have the following ...
18
votes
5answers
2k views

If Scala runs on the JVM, how can Scala do things that Java seemingly cannot? [duplicate]

I just learned about Scala yesterday, and I'd like to learn more about it. One thing that came to mind, however, from reading the Scala website is that if Scala runs on the JVM, then how is it ...
2
votes
1answer
195 views

Advantages of having numeric data types as classes rather than primitives [closed]

I was wondering about why some languages choose to implement numeric types (boolean, integers, floats, characters etc.) as classes/objects (eg. Kotlin) and some as primitive types (eg. Java). I am ...
0
votes
3answers
211 views

Why does an interface extend an interface instead of implementing it?

In Java suppose that I have interface A: public interface A { // foo } I also have interface B: public interface B extends A { // foo + bar } Why does interface B extend interface A ...
0
votes
2answers
241 views

Why does Java (and other langs too) have seemingly redundant functions like “str.startsWith(String str, int fromOffset)”?

I was wondering why Java and other programming languages implement (seemingly) redundant functions such as: "foobar".startsWith("bar", 3); // same as "foobar".substring(3).startsWith("bar"); // or ...
6
votes
1answer
106 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 ...
7
votes
1answer
347 views

Language compiled to JS – most elegant way to do synchronous-style waits

I'm trying to make (yet another) language that compiles to JavaScript. One of the features I'd like to have is the ability to perform JavaScript's async operations synchronously (not exactly ...
2
votes
2answers
221 views

When to use ANTLR and when to use a parsing library

I've always wanted to learn how to write a compiler - I've decided to use ANTLR, and am currently reading through the book (its very good by the way) I'm pretty new to this, so go easy, but the jist ...
3
votes
2answers
124 views

Why aren't field-like events implemented as a list of delegates?

tl;dr: Why are field-like events implemented as a single delegate field? Wouldn't it be more straight-forward to use a list of delegates, thereby eliminating the null special case and avoiding all the ...
0
votes
0answers
35 views

Limiting repetitions in Backus Naur forms

Is there a method using Backus-Naur Form (BNF) to limit the number of repetitions? Let's take the description of a decimial number. A decimal number will consist of 1 to many digits. Is there a ...
35
votes
4answers
3k views

Why are structs and classes separate concepts in C#?

While programming in C#, I stumbled upon a strange language design decision that I just can't understand. So, C# (and the CLR) has two aggregate data types: struct (value-type, stored on the stack, ...
3
votes
4answers
511 views

Why are cases in a switch statement not isolated? [duplicate]

As far as I can tell in all C-like languages something like this: switch(variable) { case 'a': printf("Hello "); case 'b': printf("World!"); case 'c': ...
9
votes
2answers
450 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 = ...
1
vote
1answer
99 views

Is unifiing ADTs with typeclasses possible?

When i was thinking about language design i got an idea that ADTs (Aglebraic Data Types) and typeclasses could be the same thing. They can both represent a group of types, but in haskell they are not ...
1
vote
1answer
101 views

Thinking about a language for build definitions

I want to write a little tool that parses build definitions and converts them to a ninja.build file. It should not abstract compilation like CMake or Meson, but be similar to make in that you manually ...
4
votes
2answers
304 views

Needs (in principle) C++ parenthesis around if statement condition?

In current C++ when body of if statements contain only one command then: Parenthesis around if condition are mandatory but block are optional. So, both examples are OK: if ( condition ) { return 0; ...
34
votes
2answers
9k views

What are 4th & 5th programming language generations? Are there more of them? [closed]

As it is often classified at school/college level, popular programming languages (C#, Java, C++) are all 3rd generation languages (with higher level of abstraction from the machine's physical parts). ...
1
vote
3answers
188 views

Does overriding a method affect a superclass's call?

I'm trying to understand some of the nuances of inheritance but I can't find an answer to this question. Consider the following: class SuperClass { method foo { print "in SuperClass.foo" ...
26
votes
6answers
2k views

What are the caveats of implementing fundamental types (like int) as classes?

When designing and implenting an object-oriented programming language, at some point one must make a choice about implementing fundamental types (like int, float, double or equivalents) as classes or ...
13
votes
5answers
3k views

Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?

Consider the following "C" code: #include<stdio.h> main() { printf("func:%d",Func_i()); } Func_i() { int i=3; return i; } Func_i() is defined at the end of the source code and ...
2
votes
2answers
127 views

What is meant by “redundant, but not duplicative” in the Steelman language requirements?

The Steelman language requirements have this: The language shall require some redundant, but not duplicative, specifications in programs. I think I can see the underlying idea (that re-stating ...
1
vote
0answers
51 views

Rationale behind CSS height with percentage value

I've been using CSS for a few years, but there are some "quirks" that I cannot quite fathom. One of them is the height property when specified with a percentage. To quote the CSS 2.1 Specification ...
0
votes
1answer
78 views

Is automatic conversion to collection types from non-collection variable a good idea? [closed]

Consider public void Do(string[] aBunchOfStrings) { } or public void Do(IReadOnlyList<string> aBunchOfStrings) { } Would it be a bad idea to allow the function call Do("woei"); resolve ...
1
vote
0answers
67 views

Pre-Compilation Processor:

What I want to do: Parse source code, search for a beginning and closing tag of my own definition (one that does not conflict with any defined patterns in the programming language), and then replace ...
5
votes
7answers
1k views

Why are self-hosting compilers considered a rite of passage for new languages?

I've heard in a number of places now that people expect languages to use, or at least have, a self-hosting compiler in order to deserve respect. I'm curious as to why this is. A compiler seems like a ...
9
votes
1answer
290 views

Do any notable C extensions include integer types whose behavior is independent of machine word size

An interesting characteristic of C compared with some other languages is that many of its data types are based upon the word size of the target architecture, rather than being specified in absolute ...
9
votes
1answer
2k views

Why does Scala have return but not break and continue

Scala does not have break or continue, so some loop behavior takes a bit more of thinking. Ending a loop early requires tail recursion, exceptions, or scala.util.control.Breaks (which uses ...
0
votes
2answers
751 views

What's the advantage of auto-property initializers without primary constructors?

In this chart about the features that are in or out of the next version of Roslyn (specifically, for C#), primary constructors are out, but auto-property initializers are in. The best use case I've ...
0
votes
0answers
205 views

Best way to handle language interoperability

Background In a language like F#, direct interoperability with most other .NET languages is possible. For example, it is possible to use classes written in C# directly in F#, and it is possible to ...
1
vote
3answers
266 views

Why is object-level privacy difficult to use as a paradigm, and why is it desirable?

I have heard a prominent language designer remark that no language today enforces real object privacy, and we are still unsure whether it is possible in practice to design a language that does. ...
24
votes
5answers
6k 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 ...
12
votes
5answers
2k 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 ...
35
votes
12answers
4k views

Why do most programming languages have special keyword or syntax for declaring functions? [closed]

Most programming languages (both dynamically and statically typed languages) have special keyword and/or syntax that looks much different than declaring variables for declaring functions. I see ...
0
votes
3answers
153 views

What is the most robust, extensible way to represent a contract in code? [closed]

I would like to find or create a syntax to express business contracts programmatically, and I am looking for a robust, flexible, future-resistant way to do this. A client should be able to add a ...
2
votes
1answer
448 views

Why is Throwable initCause designed to be called only once?

I find it really odd that the initCause method of Java's Throwable class can only be called once, or even not at all (if the constructor accepting a Throwable was used). This makes exception chaining ...
2
votes
2answers
487 views

What is the logic behind the use of different arrows (-> <-) in Haskell?

I've been thinking about language design lately, and reading over some of the new things in Haskell (always a nice source of inspiration). I'm struck by the many odd uses of the left <- and right ...
5
votes
1answer
152 views

Is there a better alternative than abusing the IDisposable pattern?

Consider the following (Microsoft-sanctioned) code: <% using (Html.Form<HomeController>(action=>action.Index())) { %> <input type="text" id="search" /> <input ...