Programming language where a small change in source code results in small change in behavior - programming-languages

In most programming languages making a small change in the code often results in a large change in behavior. You accidentally delete a random character and the program no longer builds, or crashes. In this sense most programming languages are chaotic.
I'm looking for a programming language where this is not the case. Such a language would be especially valuable for automatic code generation tasks.
If there is no such language, I would be happy with a link to programming language research that discusses the idea.

Related

A configurable (high/low level) programming language?

Is there a programming language that can be both high and low level? I'll elaborate...
Say, for example, you want to write an enterprise system which needs good abstractions and static typing (among other things), so you pick Java. But then, you need a portion of this system to be very low latency, so you pick C++ and do your garbage collection. Then, you want some kind of automated build script, so you quickly write something up in python.
Is there a language that could do all of these tasks, and be configurable such that one can use a GC or not if specified, the script be interpreted or not if specified, and the language can have static typing if specified? - Say, a unified syntax with optional static typing, customizable GC, and compilers..a sort of customizable Frankenstein language?
Disclaimer, I have not taken any programming language/compiler course, so this may be a noob-ish question!
Real world challenges are better dealt with multiple programming languages and programming language implementations.
Since you mentioned Python, important parts of the library are implemented in C (or in Cython) for performance reasons.
The programming languages involved on a modern Web site are at least HTML, CSS, and JavaScript, plus a templating language, plush the language used for the backend, plus the language used for services, plus SQL or the likes for querying databases.
The history of programming has recurring attempts at a single programming language for everything (ADA comes to mind), and each of them resulted in either inconsistent languages or complicated code. All of them were short-sighted.

Are there any other interesting languages frozen in time like Common Lisp?

By that I mean languages where they are stable and the standard has stopped being actively worked on, and they offer something interesting by studying them.
I am not looking for normal imperative /procedural languages that have stopped being worked on (i.e. C-like) unless of course it was something that c is based off like ALGOL.
They can be languages that run on any platform (not just unix/osx/win), it can run on a toaster for all I care, I just want it to be something interesting.
I am looking to be amazed :)
You should check an esoteric languages.
There is a site, esolangs.org that has a huge list of the esoteric languages, an informations about paradigms/concepts, a list of ideas and many more.
From the esolangs.org, the esoteric language is:
An esoteric programming language is a computer programming language
designed to experiment with weird ideas, to be hard to program in, or
as a joke, rather than for practical use.
Here are some examples from that site:
BF - using just a ><+-.,[] symbols
Piet - image as a source code

How do people go about creating their own programming languages? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 12 years ago.
Improve this question
At university I majored in compiler theory and grammars, so have a good background in this area (although a long time ago) and know that the creation of a compiler is an enormous major undertaking, at least for a language such as C++.
So I'm confused as to the large number of programming languages that seem to have been created by individuals as opposed to large groups of people working at a company. Ruby for example, according to Wikipedia it was created by one person - I don't know the language perhaps it's incredibly simple, but my point is there are bucket loads of self-created languages out there.
So how does one go about creating their own language (which isn't too simple as to be pretty useless) as an individual and not spend one's entire life doing so?
Are there any good books on the subject (not on compilers and in general, spec)?
(although a long time ago) and know that the creation of a compiler is an enormous major undertaking, at least for a language such as C++.
A lot of things have conspired to make things easier:
Computers have a lot more RAM and speed. Much of the challenge of writing early compilers was being able to do so efficiently and with a minimum of memory. That's why C can compile in a single pass: at the time, you may not have had enough memory to even fit an entire source file in it. Where before a lot of the magic of compiler-writing was optimizing your symbol table representation and parsing as fast as physically possible, now you can get by doing things much simpler and easier.
Base technology has gotten better. Most languages have nice easy to use parser libraries, high-level data structures (symbol tables are a snap if you already have a nice hashtable implementation!) and other tools to make getting a compiler or interpreter up and running much easier.
GC is ubiquitous. Most new languages being created today are garbage collected. That makes it easier to design the language (you don't have to specify detailed memory semantics). At the same time, you can target some existing GC platform like the CLR or the JVM so as the language author, you don't have to write your own GC. In fact, targeting the CLR or JVM makes your job as a compiler writer much easier in general: as a higher-level platform, the bytecode meets you halfway.
Most new languages are dynamically-typed. The majority of new languages being created are dynamically typed. Those are much easier to design and implement. I've found that a majority of the challenge in language design is designing a type system. Likewise, compiling or interpreting a static language is more of a challenge. Dynamic languages where everything is just a property bag are surprisingly easy to get up and running.
Again, computers have a lot more RAM and speed. Back in the day, if your language was to have any chance of success, it needed to compile down to efficient machine code, use memory efficiently and run fast. Otherwise it would be unusably slow. Now that computers are so much faster, even a slow language like Ruby is still fast enough for many real uses. As a compiler writer you don't need as much optimization skill as you used to.
It's also worth noting that no one is making a new language as complex as C++ these days. C++ really is near the top end of language complexity.
I have gone a little way down the route of creating my own language. I started off doing this to represent requirements, analysis and design constructs, rather than a code compiler. For this purpose even a very simple language can be useful. I found it valuable to be able to read and write such constructs in a very constrained version of English - template sentences mainly. Then it became useful to have the language machine readable and so I constructed lexers and parsers to read the language using Lex and Yacc. As I have gone I have expanded the language and its parsers to deal with the expansions.
I am aware that this is a very long way from a robust compiler for a language as extensive as C++, but illustrates one motivation for going down this route. I would suggest that your view of simple languages as being pretty useless is an overstatement. Even a very limited language can be of substantial use.
Though I have basically no experience in making languages of my own, I do have a good amount of experience learning new ones, so I could suggest this -
The programming industry is a marketplace of languages. Languages rise and fall in popularity based on their simplicity to learn and use, lack of commercial and legal restriction, applicability to real-life situations, flexibility, and power. If you want your language to be popular one day, try to go for these.
If you're designing a toy language for its own sake (as many computer scientists do), it's a interesting theoretical exercise and still quite valid, but you might not expect it to become quite as widespread.

How to go about making your own programming language? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Learning to write a compiler
I looked around trying to find out more about programming language development, but couldn't find a whole lot online. I have found some tutorial videos, but not much for text guides, FAQs, advice etc. I am really curious about how to build my own programming language. It brings me to SO to ask:
How can you go about making your own programming language?
I would like to build a very basic language. I don't plan on having a very good language, nor do I think it will be used by anyone. I simply want to make my own language to learn more about operating systems, programming, and become better at everything.
Where does one start? Building the syntax? Building a compiler? What skills are needed? A lot of assembly and understanding of the operating system? What languages are most compilers and languages built in? I assume C.
I'd say that before you begin you might want to take a look at the Dragon Book and/or Programming Language Pragmatics. That will ground you in the theory of programming languages. The books cover compilation, and interpretation, and will enable you to build all the tools that would be needed to make a basic programming language.
I don't know how much assembly language you know, but unless you're rather comfortable with some dialect of assembly language programming I'd advise you against trying to write a compiler that compiles down to assembly code, as it's quite a bit of a challenge. You mentioned earlier that you're familiar wtih both C and C++, so perhaps you can write a compiler that compiles down to C or C++ and then use gcc/g++ or any other C/C++ compiler to convert the code to a native executable. This is what the Vala programming language does (it converts Vala syntax to C code that uses the GObject library).
As for what you can use to write the compiler, you have a lot of options. You could write it by hand in C or C++, or in order to simplify development you could use a higher level language so that you can focus on the writing of the compiler more than the memory allocations and the such that are needed for working with strings in C.
You could simply generate the grammars and have Flex and Bison generate the parser and lexical analyser. This is really useful as it allows you to do iterative development to quickly work on getting a working compiler.
Another option you have is to use ANTLR to generate your parser, the advantage to this is that you get lots of target languages that ANTLR can compile to. I've never used this but I've heard a lot about it.
Furthermore if you'd like a better grounding on the models that are used so frequently in programming language compiler/scanner/parser construction you should get a book on the Models of Computation. I'd recommend Introduction to the Theory of Computation.
You also seem to show an interest in gaining an understanding of operating systems. This I would say is something that is separate from Programming Language Design, and should be pursued separately. The book Principles of Modern Operating Systems is a pretty good starting place for learning about that. You could start with small projects like creating a shell, or writing a programme that emulates the ls command, and then go into more low level things, depending on how through you are with the system calls in C.
I hope that helps you.
EDIT: I've learnt a lot since I write this answer. I was taking the online course on programming languages that Brown University was offering when I saw this answer featured there. The professor very rightly points out that this answer talks a lot about parsers but is light on just about everything else. I'd really suggest going through the course videos and exercises if you'd like to get a better idea on how to create a programming language.
It entirely depends on what your programming language is going to be like.
Do you definitely want it to be compiled? There are interpreted languages as well... or you could implement compilation at execution time
What do you want the target platform to be? Some options:
Native code (which architectures and operating systems?)
JVM
Regular .NET
.NET using the Dynamic Language Runtime (like IronRuby/IronPython)
Parrot
Personally I would strongly consider targeting the JVM or .NET, just because then you get a lot of "safety" for free, as well as a huge set of libraries your language can use. (Obviously with native code there are plenty of libraries too, but I suspect that getting the interoperability between them right may be trickier.)
I see no reason why you'd particularly want to write a compiler (or other part of the system) in C, especially if it's only for educational purposes (so you don't need a 100-million-lines-a-second compiler). What language are you personally most productive in?
Take a look at ANTLR. It is an awesome compiler-compiler the stuff you use to build a parser for a language.
Building a language is basically about defining a grammar and adding production rules to this grammar. Doing that by hand is not trivial, but a good compiler-compiler will help you a lot.
You might also want to have a look at the classic "Dragon Book" (a book about compilers that features a knight slaying a dragon on the front page). (Google it).
Building domain specific languages is a useful skill to master. Domain specific languages is typically not full featured programming language, but typically business rules formulated in a custom made language tailor made for the project. Have a look at that topic too.
There are various tutorials online such as Write Yourself a Scheme in 48 hrs.
One place to start tho' might be with an "embedded domain specific language" (EDSL). This is a language that actually runs within the environment of another, but you have created keywords, operators, etc particularly suited to the subject (domain) that you want to work in.

what is a programming language?

Wikipedia says:
A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that specify the behavior of a machine, to express algorithms precisely, or as a mode of human communication.
But is this true? It occurred to me in the shower this morning that a programming language might just be a set of conventions, something that both a human and an appropriately arranged compiler can interpret. If that's the case, then isn't it this definition of a programming language misleading? If that isn't the case, then what's the difference between a compiler and the language it compiles?
Thanks!
z.
A programming language is exactly that set of conventions, but I don't see why that makes the Wikipedia entry misleading, really. If it makes you feel better, you might edit it to read something like:
A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to define programs that specify the behavior of a machine, to express algorithms precisely, or as a mode of human communication.
I understand what you are saying, and you are right. Describing a programming language as a "machine-readable artificial language designed to express computations that can be performed by a machine" is unnecessarily specific. Programming languages can be more broadly generalized as established descriptions of tasks (or "a set of conventions") that allow one entity to control the behavior of another. What we traditionally identify as programming languages are just a layer of abstraction between machine code and programmers, and are specifically designed for electronic computers.
Programming languages are not limited to traditional computers (see the K'NEX Computer), and aren't even necessarily limited to computational devices at all. For example, when I am pleased with my dog's behavior, he gets a treat. When I am displeased, he gets nothing. Over time the dog learns the treat/no treat programming and I can use the treats to control his behavior (to an extent).
I don't see what is different between what you are asking...
It occurred to me in the shower this morning that a programming language might just be a set of conventions, something that both a human and an appropriately arranged compiler can interpret.
... and the Wikipedia definition.
The key is that a programming language is just "a machine-readable artificial language".
A compiler does indeed act as an effective specification of a language in terms of a reduction to machine code - however, as it's generally difficult to understand a language by reading the compiler's source, one generally considers a programming language in terms of an abstract processing model that the compiler implements. This abstract model is what one means when one refers to the programming language.
That said, there are indeed many languages (Hi there, PHP!) in which the compiler is the only specification of the language in existence. These languages tend to change unpredictably at times as compiler bugs are fixed or introduced.
Programming languages are an abstraction layer that helps insulate the programmer from having to talk in electrical signals to the computer. The creators of the language have done all the hard work in creating a structure (language) or standard (grammar, conjugation, etc.) that then can be interpreted by a compiler in terms that the computer understands.
All programming languages are really nothing more than domain specific languages for machine code or manipulating the registers and memory of a processing entity.
This is probably the true explanation of what a programming language really is:
Step 1: Think of a language and its grammar, which is a set of rules for making syntactically valid statements using the language. For example, a language called GRID has tiles {0,1} as its alphabet and grammar rules that make sure every GRID statement has equal length and height.
Step 2 (definition of program): GRID, so far, is useless. I'd dare to think of any valid statement of GRID as just data. We need to add something else to GRID: a successor function. So GRID={Grammar, alphabet, successor function}. To make this clear, lets use the rules of "The Game of Life" as successor function.
Step 3: The Game of Life is actually Turing Complete, so GRID={Grammar, alphabet, successor function = GOL} can perform any computation that is computable.
A programming language is nothing but a language with a successor function. The environment that evaluates a valid statement of the language(program) does nothing but follow those successor functions. Variables, for example, are things whose successor functions = (STAY THE SAME)
Computers are just very fast environments ;)
Wikipedia's definition might have been taken out of context. For one thing, only programs written in machine code are machine-readable. Otherwise, you need a compiler to convert C++, Java or even assembly code to machine code so the computer can carry out your instructions. Unless you include comments that are only readable to humans, or unless you are strictly discussing a topic within the realm of your program, programming is insufficient for human communication.

Resources