Questions involving the design and structure of programming languages.

learn more… | top users | synonyms

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
153 views

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

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
179 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
220 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 ...
5
votes
1answer
92 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
323 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
131 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
84 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
26 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 ...
34
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
500 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': ...
7
votes
2answers
380 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
88 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
93 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
251 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
162 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" ...
25
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
2k 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 ...
1
vote
2answers
112 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
45 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
61 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 ...
4
votes
7answers
848 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 ...
7
votes
1answer
263 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
1k 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
505 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
137 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
2answers
214 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. ...
20
votes
5answers
4k 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 ...
8
votes
5answers
1k 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
148 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 ...
1
vote
1answer
300 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
391 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 ...
4
votes
1answer
135 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 ...
-1
votes
1answer
311 views

Are there any scenarios where the 'Dispose Pattern' shouldn't be used on an Object which contains managed and un-managed resources?

MSDN says that to properly clean up an object which contains managed and un-managed resources, you need to implement the 'Dispose Pattern'. Given that the class implements the IDisposable interface, ...
4
votes
4answers
1k views

How does Python compile some its code in C?

I read that some constructs of Python are more efficient because they are compiled in C. https://wiki.python.org/moin/PythonSpeed/PerformanceTips Some of the examples used were map() and filter(). I ...
1
vote
3answers
85 views

Property-level value transformation for indirect object casting

Does any programming language exist to support the explicit, property-level object copy? For example, assume this code: public class Student { public string Name { get; set; } public ...
2
votes
1answer
311 views

How do you make decorators as powerful as macros?

Quick background: I am designing a Pythonic language that I want to be as powerful as Lisp while remaining easy to use. And by "powerful", I mean "flexible and expressive". I've just been introduced ...
4
votes
5answers
960 views

Does this kind of programming language exist?

I'm thinking about creating my own pet programming language, and I have been wondering if similar language already exists. The basic idea is that the language itself would be dynamically typed with ...
6
votes
7answers
969 views

Why isn't there a next operation on enums?

In most popular programming languages like Java and C# there is a way to define enums, which are essentially datatypes with a fixed set of values, e.g. DayOfWeek. The problem is, given a value, e.g. ...
4
votes
3answers
582 views

Functional programming strategies in imperative languages

I've been convinced for awhile now that some strategies in functional programming are better suited to a number of computations (i.e immutability of data structures). However, due to the popularity of ...
42
votes
7answers
4k views

Why is the finalize method included in Java?

According to this post, we should never rely on the finalize method to be called. So why did Java include it in the programming language at all? It seems like a terrible decision to include in any ...
8
votes
3answers
1k views

Is duplicate syntax for defining named functions a bad language design decision?

I am modelling a programming language for fun, and the syntax is heavily influenced by Scala - specifically function definitions. I have encountered a design problem because my language does not ...
43
votes
6answers
9k 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
5answers
595 views

Should sanity be a property of a programmer or a program? [closed]

I design and implement languages, that can range from object notations to markup languages. In many cases I have considered restrictions in favor of sanity (common knowledge), like in the case of ...
0
votes
2answers
2k views

Why doesn't Ruby have implicit conversion of Fixnum into String?

Ruby normally makes things easy. However, it doesn't allow implicitely converting a number to a string: 2.0.0p247 :010 > "a"+1 TypeError: no implicit conversion of Fixnum into String Why is this ...
0
votes
2answers
254 views

Benefits of Java in education? [closed]

I hope this isn't too off-topic and/or opinion based. I'm looking for examples and reasons why Java is an acceptable language for education purposes. Here's why: I learned programming on my own in C ...
5
votes
4answers
722 views

Why do arrays in Java not override equals()?

I was working with a HashSet the other day, which has this written in the spec: [add()] adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : ...