Questions involving the design and structure of programming languages.

learn more… | top users | synonyms

2
votes
4answers
120 views

Is the var token necessary to signal variable declaration?

When creating a variable foo, Python lets you just write foo = bar. However many languages, like C# or JavaScript, require additional syntax like var foo = bar or foo := bar to signal the same thing. ...
2
votes
1answer
64 views

Does exception handling belong at the lowest level of the runtime?

I'm designing a fairly simplistic stack-based programming language, and implementing it in Python. (no link, because it's not fully implemented yet.) The language itself is essentially intended to be ...
6
votes
8answers
612 views

Can “return this” pattern be optimized to no cost performance?

return this (or similar construct) allows method chaining. Lack of it is painful, because you have to write such code (C#): var list = new List<string>(); list.Add("hello"); list.Add("world"); ...
1
vote
2answers
155 views

For what reasons Java and C# initialize static data on demand?

I am reading "The Go Programming Language" right now and I have read package initialization chapter which tells (or I read it wrong) that Go uses eagerly initialization. So in time we saw say C++ ...
2
votes
3answers
151 views

Why does the overriding rule of C++ not care about visibility changes?

In C++, it is possible to write an overriding for a base class's method even if the visibility declaration of the two don't match. What are the possible design considerations under the decision of not ...
8
votes
3answers
337 views

How useful is C's “true” sizing of variables?

One thing that always intuitively struck me as a positive feature of C (well, actually of its implementations like gcc, clang, ...) is the fact that it does not store any hidden information next to ...
2
votes
2answers
80 views

C# / VB.NET build expression trees only from lambda expressions — why?

Based on the context, C# can generate the expression tree for a LambdaExpression from lambda expression syntax: Expression<Func<string, int>> expr1 = s => s.Length; as can VB.NET: ...
1
vote
1answer
98 views

What was the reason behind using quotes in Go's import statements?

The usage of quotes in Go's import statement strikes me as unnecessary. Typical Go import statements look like: import "foo/bar" import other_name "foo/bar" import ( "foo/bar" x "foo/baz/bar" ...
-1
votes
2answers
75 views

Hypothetical extension to C# property initializer syntax

In C#, when you call a constructor, you can add one or more property initializers in curly braces: var foo = new Bar() { Armpit = new Flapdoodle() { Limpet = 2 } }; What if that feature were ...
2
votes
2answers
105 views

Should the Vector type inherit from the Array type in an environment where both are first-class objects

I have created a programming language that is based on java for a personal project. The language already has generic classes and functions and the generics are completely compatible with primitive ...
6
votes
3answers
269 views

Why is the most common integer number 32 bits, but the most common floating point number 64 bits?

Coming from a Java and C# background, I've learned to use int (32 bits) whenever I need a whole number, and double (64 bits) when dealing with fractional values. Most methods from their respective ...
1
vote
1answer
155 views

Are decorators/annotations the result of bad design decisions?

Talking generic, there are programming languages who make more or less use of annotations and decorators. Be it to add type information to variables in a dynamically typed language or to add ...
5
votes
4answers
401 views

Why use plus equals += for event registration?

In C#, you register an event like: window.onClick += myHandler; But why use this instead of a "register" method that takes your handler and registers it. E.g.: window.registerOnClick(myHandler); ...
-1
votes
1answer
115 views

Naming choice in Java — clone vs. copy [closed]

We have "copy constructor" but "clone method". This asymmetry in naming puzzles me -- does anyone know for what reason the method was not named "copy" (and interface per analogy "Copyable")? This ...
3
votes
1answer
260 views

Will ECMAScript add classes to JavaScript? What does this mean? [closed]

I heard that some sort of class system will be added to JavaScript with ECMAScript and I find that a little confusing, because I've just finished reading a JS book, JavaScript, The Good Parts by ...
5
votes
3answers
450 views

Why do you need “self.” in Python to refer to instance variables?

I have been programming into a number of languages like Java, Ruby, Haskell and Python. I have to switch between many languages per day due to different projects I work on. Now, the issue is I often ...
0
votes
2answers
189 views

Does Python have any features which can be used for encapsulating private data?

Usually in OOP world we are told that modularity is a good practice and keeping loose coupling between module is a great thing. Encapsulation helps us achieve this loose coupling. In Java ...
1
vote
0answers
35 views

Is there an advantage to defining a metasyntactic variable type? [closed]

Is there (or has there ever been) a language that implements an object that represents, "don't pay attention to this, it's just a placeholder value for now"? null is for where the thing you're asking ...
-3
votes
1answer
182 views

Designing a programming language, seeking simple and logical parameter behavior [closed]

I am designing a programming language, and would want to make it as simple as possible, conforming to layman's logic. I've been using many programming languages, although the last few years I've been ...
4
votes
1answer
182 views

What would break if there was an option to make undefined not convert to any other type in JavaScript?

The biggest issue I run into in JavaScript is silent typos. For example, the other day I had a variable inIframe. Somewhere else I typed isIFrame. 10-15 mins of debugging later I found it and changed ...
29
votes
10answers
7k views

Why is Math.Sqrt() a static function?

In a discussion about static and instance methods, I always think, that Sqrt() should be a instance method of number types instead of a static method. Why is that? It obviously works on a value. // ...
0
votes
2answers
314 views

Why doesn't Java implement a better way of handling getters and setters? [closed]

Getters and setters are everywhere in Java, but they are managed in a horribly outdated way. Simply put: Why doesn't a newer version of Java enable a simpler syntax for managing it? Even if this ...
-4
votes
4answers
288 views

Why aren't named switch statements a language feature? [closed]

I could imagine the below code being somewhat useful. Is there a reason this pattern hasn't made it into programming languages? To be clear the string was just what I chose as an example you could ...
2
votes
3answers
407 views

Is `isNaN`' a bad design or a has-to-be design with tradeoffs?

My first programming language is python. And recently I'm learning C and javascript. In javascript, there is a design which confused me a lot, default the function isNaN. Put aside its weird ...
-2
votes
0answers
260 views

Reasons to want false-negatives when comparing strings (or string references)? [duplicate]

Java programmers know that new String("some-text") == new String("some-text") evaluates to false because two different objects/references are being compared [and that String.equals should be used to ...
1
vote
2answers
222 views

What are the justifications for annotations in a programming language? [closed]

After spending a great deal of time writing C# and looking at Java, it seems to me that annotations are just an ugly code smell that introduce another conceptual layer that could easily be replaced by ...
2
votes
2answers
171 views

Why not expose activation records as data types? [closed]

Scoped languages tend to store the local variables of a given scope or function together in a data structure known as an activation record. Stack frames are examples of instances of activation ...
7
votes
1answer
487 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 ...
0
votes
0answers
25 views

Harmony (and general language) Feature Adoption [duplicate]

Looking at the browser support for the let operator on developer.mozilla has led me to wonder if there is any data which might provide insight into programming language feature adoption rates and/or ...
0
votes
0answers
72 views

When and when not to use OOP in Javascript? [duplicate]

This post suggests that javascript code should be written in object oriented design. He gives a trivial example of making some ajax call and alerting the response. From the world I come from (c#) he's ...
1
vote
4answers
201 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
923 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
125 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
263 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
398 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 ...
1
vote
1answer
98 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
138 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
64 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 ...
3
votes
3answers
349 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
329 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
78 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 ...
28
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
131 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 ...
21
votes
5answers
3k 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
260 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
246 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
269 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 ...
7
votes
1answer
138 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
388 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 ...