We’re rewarding the question askers & reputations are being recalculated! Read more.
28

Many of these tools do work directly with the abstract syntax tree (or rather, a direct one-to-one visualisation of it). That includes Blockly, which you've seen, and the other block-based languages and editors like it (Scratch, Pencil Code/Droplet, Snap!, GP, Tiled Grace, and so on). Those systems don't show a traditional vertex-and-edge graph ...


24

Upcasts always succeed. Downcasts can result in a runtime error, when the object runtime type is not a subtype of the type used in the cast. Since the second is a dangerous operation, most typed programming languages require the programmer to explicitly ask for it. Essentially, the programmer is telling the compiler "trust me, I know better -- this will be ...


14

The null value as a default present everywhere is just a really broken idea, so forget about that. You should always have exactly the concept that best describes your actual data. If you need a type which indicates "unkown", "nothing", and "value", you should have precisely that. But if it does not fit your actual needs then you should not do it. It is a ...


11

First class types enable something called dependent typing. These allow the programmer to use values of types at type level. For example, the type of all pairs of integers is a regular type, while the pair of all integers with the left number smaller than the right number is a dependent type. The standard introductory example of this is length encoded lists (...


10

The pattern you're talking about, where objects know how to clean their resources up, falls into three relevant categories. Let's not conflate destructors with finalizers - only one is related to garbage collection: The finalizer pattern: cleanup method declared automatically, defined by programmer, called automatically. Finalizers are called ...


9

Bjarne Stroustrup writes in his The Design and Evolution of C++ book (item 3.5.1): At this point, the object model becomes real in the sense that an object is more than the simple aggregation of the data members of a class. An object of a C++ class with a virtual function is a fundamentally different beast from a simple C struct. Then why did I not ...


8

This issue is strongly connected to the notion of what it means to be an instance of a class. In strict Object-Oriented terms, a class has an associated invariant: a predicate which always holds true on exit from a (public) method of the class. Such a notion is central in ensuring that inheritance is well-defined, for example (it's part of the Liskov ...


8

There are two kinds of programmers: Those who for whatever reason never, ever use goto, and go to any lengths to avoid it, and those who use goto in one of the very rare situations where it is the best solution. (Someone said here in a comment that goto could be misused and programmers would find ways to misuse it - but those people are not programmers). ...


8

The goto in itself isn't "evil", it is just easy to misuse. A famous paper by Knuth is "Structured Programming with goto statements", ACM Computing Surveys 6:4 (dec 1974), 261-301. For example the Linux kernel uses goto often, in a disciplined and safe way.


8

You're on the right track: people have come up with the same way to do this. The general concept is known as abstract types. With the Church encoding, the type of a pair of elements of types $a$ and $b$ is polymorphic: it has the type $\forall x, \mathtt{Pair} \, a \, b \, x$ where $x$ is the type of the destructor's continuation. The type family you're ...


7

Given your very strict interpretation of limited memory size, limiting also the size of integers, one consequence is that it is not possible to play encoding games with integers (such as Gödel enumerations or encodings). Another consequence is that you cannot have a way of retrieving the address of a memory location in order to make pointers. The reason is ...


7

Most algorithms and forms of business logic can fit nicely into the control structures that are built into modern languages, in large measure because such structures were designed to fit the needs of common applications. Some applications, however, need to implement algorithms or business logic that do not fit any such control structures. Programs are ...


7

Things like strings and dates are naturally values. In C++ terms, we expect them to have a copy constructor, an assignment operator, and an equality operator, but we never expect to take their address. Hence, we don't expect them to be individually allocated on the heap. Virtual methods make no sense. Domain objects are naturally references. C++ ones have ...


7

I don't think there is any research (with good methodology) on this. The language I'd most expect to have actually thought about this and made an empirically-based decision is the Quorum programming language. It uses a "type before variable name" approach (though it does put the return type of a method declaration after the parameter list). However, what I ...


7

Today, most people who learn a programming language know very little mathematical notation and are more familiar with other programming languages, and with symbols that are available on their computer keyboard. Of course, this wasn't the case in the 1950s and 1960s when some of the major programming language families that exist today appeared. A lot of ...


6

Now, is it right that only identifiers and literals have to be separated by delimiters or whitespace? How do I ensure that? If by "right" you mean it is the case in every programming language, then no, it is not right, and probably no non-trivial lexical statement would be either. In many languages, integer literals do not have to be separated from a ...


6

Java was designed to allow execution of subsections of a program's code in security constrained environments. The way this requirement was implemented was by setting a "SecurityManager" on a thread that is given access to the parameters of certain critical operations (eg opening a file) and asked whether or not the operation should be allowed to go ahead. ...


6

Here are three context-sensitive syntaxes actually found in programming languages. I don't believe I've ever seen a language which has types, names and values distributed as per your example, but it could certainly exist, and I'm sure there are even less readable syntaxes which are possible. The following are at least somewhat readable: Syntactic whitespace,...


6

At least two reasons: Because source code is a much more concise representation. Laying out an AST as a graph would take up a lot more visual real estate. Programmers prize having as much context as possible -- i.e., having as much code present all at once on the screen at the same time. Context helps them better manage complexity. (That's one reason ...


6

Character and String are conceptually very, very different. Google for "inheritance vs. composition" - you seem to think that Character and String should be connected via inheritance, but in reality a String is composed of 0, 1 or more Characters. And to throw a spanner in the works: Strings are often large, and String operations must be very efficient. ...


5

I think you're missing the notion of continuation. Although your compiler may not rely on that notion, as a compiler designer with a functional language as source or intermediate (or target) language, it's important to understand that notion and keep this in mind. The continuation of a piece of code describes what the code exits to. In imperative terms, it ...


5

So I managed to solve this issue today. The code for my while loop: while (condition: ~>bool) (body: ~>void) => void { if condition { body; while condition body; }; } When I go to build this into CIL (a stack based runtime, important for the psuedocode, not important for the answer) it looks like: ldarg 0 <build ...


5

In a nutshell Finalization is not a simple matter to be handled by garbage collectors. It is easy to use with reference counting GC, but this family of GC is often incomplete, requiring memory leaks to be compensated for by explicit triggering of destruction and finalization of some objects and structures. Tracing garbage collectors are much more effective,...


5

If your language has a small set of functions and there is no mechanism for adding other ones, then you could include the function names as keywords. But that's not a very likely scenario, unless your "language" is just a desk calculator (and even then, these days many calculators allow you to define functions). So in general, it's not going to be feasible ...


5

It can be done. Here's a presentation explaining the language and how the compiler works (so far). You can play with an asm.js version at http://hackerfoo.com/eval.html


4

Here's the problem: You always need some way to resolve ambiguity when there are overlapping clauses There is no easy syntactic way to ensure that clauses don't overlap. So, if you can think of a way for the behavior of if to be well defined when there are overlapping clauses, that doesn't depend on the ordering of the clauses, then you can do what you're ...


4

There is no top-down or bottom-up typing strategy when defining a language. It is an implementation issue. A type system will only define operator operand constraints on your AST. The kind constraints is fixed by the type system and is part of the design of the language. It can be very simple as in older languages, or be a sophisticated logical system. Even ...


4

I always felt like the reason is expressed by Alan Kay in his OOPSLA 1997 keynote, when he talks about Dijkstra's paper. I am not taking sides here but the tension expressed there seems to be prevalent in politics of CS, when it comes to Europe vs America. Algol represents European way of doing CS, and really most of the code was written in America. So no ...


4

The object destructor pattern is fundamental to error handling in systems programming, but has nothing to do with garbage collection. Rather, it has to do with matching object lifetime to a scope, and can be implemented/used in any language that has first class functions. Example (pseudocode). Suppose you have a "raw file" type, like the Posix file ...


4

As far as I know, the value null in C# is a possible value for some variables, depending on its type (am I right?). For example, instances of some class. For the rest of the types (like int, bool, etc) you can add this exception value by declaring variables with int? or bool? instead (this is exactly what the Maybe constructor does, as I will describe next). ...


Only top voted, non community-wiki answers of a minimum length are eligible