What would your ideal programming language be like ?

You can talk about almost anything that you want to on this board.

Moderator: Moderators

User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

What would your ideal programming language be like ?

Post by Bregalad »

If I were to design my own programming language, which I am not, but who knowns, I'd make it using rules that are as simple as possible, using as few operators as possible built into the language.

This is pure brainstorming but there is several ideas I have, which are mainly made of what I don't like about C and C++ replaced, and what I like being kept.

I'd make it somehow C-like, but with the following differences/simplifications :
  • { and } are not used, ( and ) are used instead, so that they are easy to access on a swiss keyboard (I know { and } are easy to access an american keyboard, but they aren't for me).
  • Operators are all overloadable for any types
  • bool is the only type, other types are built using solely bool, array, struct, union and pointers. char for example would be a typedef for an array of 8 bool
  • No opeartor such as '+' or '-' is build in, they are just part of a standard library that can be changed if the user wishes to. Only the boolean &, | and ^ are implemented by default. Everything else sits inside a library.
  • Assignement is made with <- operator instead of = which is confusing because it could mean equality.
  • Arrays are dereferenced with () instead of []
  • Structs and unions are acessed with () just like arrays (basically, everything is always deferenced with ())
  • There is no const-correctness, the compiler determines whenever a "variable" is constant and applies the appropriate optimisations when it is
  • To avoid the passage by value or reference issue, the arguments of a function are always readonly (i.e. const). If the user wishes to modify them he has to make a local copy manually
  • Inside for loops, ',' is used instead of ';' to separate instructions
  • It's easy to do pseudo-OO when there's a need to by adding function pointers in a struct, yet it's not "pure" OO or any bullshit like that
  • The syntax for function pointers is fixed so that it makes sense (I don't know how yet I admit)
  • The while part of a do/while loop is optional, when only "do" is used that's an infinite loop
  • Returned values are named, and are usable as local variables. (if no name is given "return" is used automatically)
  • It's possible to return multiple values (a.k.a. unnamed structs) easily
  • Compile time constant automatically decay in an usable array of bits
  • Type modifiers are always arround the type name instead of the declaration name (i.e. bool[8] i, not bool i[8] for declaring a 8-bit integer)
In order to be compilable it would requires heavily on automatic vectorisation, but that's not much problems with todays' PCs.

Here you are a sample at what the language I have in mind might be looking :

Code: Select all

typedef char bool[8];	// Define a 8-bit integer type

char operator==(char a, char b)
(
	return <- (a(0) == b(0)) &
	       (a(1) == b(1)) & 
	       (a(2) == b(2)) &
	       (a(3) == b(3)) &
	       (a(4) == b(4)) &
	       (a(5) == b(5)) &
	       (a(6) == b(6)) &
	       (a(7) == b(7));
)

char operator!=(char a, char b)
(
	return <- !(a==b);
)

// Unsigned comparison
char operator<(char a, char b)
(
	if(a(7) != b(7)) return b(7);
	if(a(6) != b(6)) return b(6);
	if(a(5) != b(5)) return b(5);
	if(a(4) != b(4)) return b(4);
	if(a(3) != b(3)) return b(3);
	if(a(2) != b(2)) return b(2);
	if(a(1) != b(1)) return b(1);
	if(a(0) != b(0)) return b(0);
)

bool operator<=(char a, char b)
(
	if(a == b) return <- true;
	else return <- a<b;
)

bool operator>=(char a, char b)
(
	return <- !(a<b);
)

bool operator>(char a, char b)
(
	return <- !(a<=b);
)

// Now we can compare 8-bit integers. Let's create a library so that we can add and substract them

(bool sum, bool cin) full_adder(bool a, bool b, bool cin)
(
	sum <- a ^ b ^ cin;
	cout <- (a ^ b & cin) + (a & b);
)

// Define incrementation (using auto-vectorisation) the compiler optimizes the incrementation in an inc instruction
(char res) operator++(char a)
(
	bool carry;
	(res(0), carry) <- full_adder(a(0), 1, 0);
	(res(1), carry) <- full_adder(a(1), 0, carry);
	(res(2), carry) <- full_adder(a(2), 0, carry);
	(res(3), carry) <- full_adder(a(3), 0, carry);
	(res(4), carry) <- full_adder(a(4), 0, carry);
	(res(5), carry) <- full_adder(a(5), 0, carry);
	(res(6), carry) <- full_adder(a(6), 0, carry);
	(res(7), carry) <- full_adder(a(7), 0, carry);
)

(char res) opearator+(char a, char b)  (using auto-vectorisation the compiler optimises this into a simple add operation)
(
	char i;
	bool carry;
	for(i <- 0, i != 7, ++i)
	(
		(res(i), carry) <- full_adder(a(i), b(i), 0);
	)
)

// Now let's define a vector type
typedef char[8] vector;

// We can add vectors
(vector res) operator+(vector a, vector b)
(
	char i;
	bool carry;
	for(i <- 0, i != 7, ++i)
	(
		(res(i), carry) <- full_adder(a(i), b(i), 0);
	)
)

// Let's create a 8x8 matrix type
typedef vector[8] mat64_t;

// We can add matrixes
(mat64_t res) operator+(mat64_t a, mat64_t b)
(
	char i;
	bool carry;
	for(i <- 0, i != 7, ++i)
	(
		(res(i), carry) <- full_adder(a(i), b(i), 0);
	)
)


(vector result) bubble_sort(vector data)
(
	result <- data;		// data CANNOT be modified because it is automatically called as a const-reference, so we have to copy here
	bool sorted;
	do
	(
		sorted <- true;
		for(int i <- 0, i<7, ++i)
		(
			if(result(i) < result(i+1))
			(
				int temp <- data(i);
				data(i+1) <- result(i);
				sorted <- false;
			)
		)
	)
	while(!sorted);		//If we ommited this line the program would still be legal but would never exit, it would *NOT* be a syntax error
)

void main()
(
	bool[8] a <- (true, false, false, true, true, false, true, false);	// primitive way of assigning 154 to a 8-bit value
	char b <- 154;				// The intent is here more clearer
	bool[8] c <- 154;			// It makes it explicit the value is a 8-bit one
	char d <- 0x94;				// Still the exact same, using hexadecimal notation
	char e <- (154);			// Equivalent, an array of 1 element is the same as the element iself
	char f <- (1, 0, 0, 1, 1, 0, 1, 0);	// Yet another way to do it, each digit turns into an array of 1 bit and is thus equivalent

	char g <- b + c;		// How to make computations and store them in variables
	if(b)		// ERROR, b is not boolean type
	(
	)
	if(b == 0)	// Correct, as 0 will automatically be converted to an array of the correct size (here 8)
	(
	)

	vector h <- 0;				// Incorrect, because cannot convert from bool[1] to bool[8][8]
	vector i <- (1, 2, 3, 4, 5, 6, 7, 8);	// This is correct
	vector j <- (((1, 2, 3, 4, 5, 6, 7, 8)));	// Also correct, the type is bool[n][8][1][1] which decays into bool[8][8] as arrays of 1 elements are the same as the element itself

	char[6] k <- ('h', 'e', 'l', 'l', 'o', 0);	// How to build a string
	char[6] l <- "hello";			//Would somehow be equivalent
	vector m <- "hello  ";		// Correct, with the null termination this makes a 8-character array
	vector n <- "hello";		// Incorrect, cannot convert bool[8][6] into bool[8][8]
	vector o <- m+n;		//Legal ! We add vectors with a simple '+' !

	n <- sort(m);			// The vector n is directly tied to "result", so no more than 1 copy was necessary
	m <- sort(m);			// The copy is optimized out, as the function notices the references points to the same variable

	mat64_t p <- (m, n, o, m, n, o, m, n);						//Define a 8x8 matrix
	mat64_t q <- (m+n, o+n, m+o, p(3), p(2), o, m, n, (1, 2, 3, 4, 5, 4, 3, 2));	//Define another 8x8 matrix
	mat64_t r <- p + q;					// Legal ! We add matrixes with a '+' !

	// Now let's assume types like string, int, etc.. are defined, with operators overloaded so that they are usable like in C
	// As well as a print() function
	struct
	(
		string name,
		int    age,
		double height,
	) student <- ("max", 21, 1.78);	// Affects fields globally

	++student(age);			// Affects fields individually
	student(heigth) <- 1.88;

	// Can be done via a normal function overloaded for multiple types
	print(student(name));		//Prints max
	print(student(age));		//Prints 22
	print(student(heigth));		//Prints 1.88

	// Can also be done via operator overloading of << if one prefers
	print << student(name) << student(age) << student(height);
)
So basically the deal is to make the language have as few rules as possible, and using as few symbols as possible in order to let the user overloads them for his own private usage. Standard library would of course provide integer and floating point possibilities, as well as the guarantee they get auto-vectorized whenever possible.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: What would your ideal programming language be like ?

Post by tepples »

If you want as few symbols as possible, I'd give Scheme a try.

C and C++ allow using <% and %> instead of { and } respectively.

Your recommendation to use the call operator () for indexing would rule out making a type that can be both called and indexed.

Your recommendation to build everything out of bool might work in a hardware description language such as Verilog. I don't see how it'd be practical on byte-oriented machines, as my compiler theory class never covered auto-vectorization. Nor can I see how a "pointer" would work in Verilog. I must be missing something basic.

How can the compiler determine whether a variable is constant when the variable is exported to other separately compiled modules, either through static allocation in a global namespace or through a pointer? Or would you mandate link-time optimization?
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: What would your ideal programming language be like ?

Post by tokumaru »

tepples wrote:C and C++ allow using <% and %> instead of { and } respectively.
Doesn't C allow you to define substitutes for anything you want? You'd obviously not be able to use (), but you should be able to use 2 character combinations instead of {}.
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: What would your ideal programming language be like ?

Post by lidnariq »

We're not (yet) talking about the, er, amazing things the preprocessor supports. Just ordinary C digraphs.
Sik
Posts: 1589
Joined: Thu Aug 12, 2010 3:43 am

Re: What would your ideal programming language be like ?

Post by Sik »

Digraphs are harder to read though. Also don't forget iso646.h (which incidentally replaces the boolean symbols because they're hard to type on some layouts, but honestly probably also because a lot of languages just use keywords for them instead).
Bregalad wrote:There is no const-correctness, the compiler determines whenever a "variable" is constant and applies the appropriate optimisations when it is
Const correctness is not for optimization, it's to prevent programmers from accidentally modifying a value that's supposed to remain constant (try to modify a const value and you'll get a rather blatant compile-time error, which will save you lots of time tracking down the problem).
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Re: What would your ideal programming language be like ?

Post by Bregalad »

Your recommendation to use the call operator () for indexing would rule out making a type that can be both called and indexed.
Yes, it makes it clearer and less messy in my opinion. I like to see arrays as the same as functions that can return one of their elements (idem for structs and unions). What type would be useful to be both indexed and called ? I really don't see any.
Your recommendation to build everything out of bool might work in a hardware description language such as Verilog. I don't see how it'd be practical on byte-oriented machines, as my compiler theory class never covered auto-vectorization. Nor can I see how a "pointer" would work in Verilog. I must be missing something basic.
No actually it was just an idea that I brought to the very extreme : Use the bare minimum bones in order to do everything. Maybe an integer type of some sort that is already build in the language will be needed in order to be efficient after compiling. The type system in C is downright awful.
as my compiler theory class never covered auto-vectorization
I don't know much but basically you detect if the input looks like something you expect it to be, and if it does then you replace a very large/complex block by a single "complex" instruction.

Here the compiler would have to detect adder functions working on boolean, tell itself "hey, that is an adder", and replace it with actual add instructions. Same for multiply, etc...
User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: What would your ideal programming language be like ?

Post by Myask »

Bregalad wrote:Use the bare minimum bones in order to do everything.
There are Turing-complete One-instruction-set computer possibilities. So they claim.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Re: What would your ideal programming language be like ?

Post by Bregalad »

This is a machine language, not a high-level language. The goal was to
1) Have the bare minimum build-int and
2) Provide you tools to have powerful constructs in a nested-doll fashion

You clearly missed 2) here.

Also (not directed at you personally) : PLEASE don't quote/link to wikipedia again and again as if it was the only source of information in the world. I miss the good old time when nobody knew this site existed.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: What would your ideal programming language be like ?

Post by tepples »

Bregalad wrote:Provide you tools to have powerful constructs in a nested-doll fashion
I'd be interested to see a proof of concept compiler that can unnest them on common hardware.
Sik
Posts: 1589
Joined: Thu Aug 12, 2010 3:43 am

Re: What would your ideal programming language be like ?

Post by Sik »

Bregalad wrote:The type system in C is downright awful.
Which was the direct result of needing to make the language both portable but while still cattering to every single strength of every system since computers were just way too slow back then. If it was me in this day and age the only integer types allowed would be int8, int16, int32, int64, uint8, uint16, uint32 and uint64, i.e. fixed size integers (although it makes one wonder what size_t should be replaced with, because e.g. uint64 would become useless if we ever get 128-bit addresses). With floating point it's more tricky because there still isn't much of an agreement (e.g. not all systems are IEEE compliant in their behavior), and then there's the whole issue with strings but most of their problems actually come from flaws in arrays in general (e.g. having to be nul terminated because arrays don't specify their size).

There's also the whole integer promotion issue, but this is more tricky. No implicit casting can mean lots of verbose code adding casting where needed (e.g. when calculating intermediate results), but automatically promoting types can result in compatibility issues in the long term as new platforms get implemented. Yikes.
User avatar
mikejmoffitt
Posts: 1352
Joined: Sun May 27, 2012 8:43 pm

Re: What would your ideal programming language be like ?

Post by mikejmoffitt »

I think you might like VHDL - a few of your points (which are things that drive me insane that I don't like at all!) remind me of it.
zzo38
Posts: 1080
Joined: Mon Feb 07, 2011 12:46 pm

Re: What would your ideal programming language be like ?

Post by zzo38 »

My kind of ideal programming language would probably be like:
  • Most things are done by macros (in ways more powerful than C macros).
  • Control over optimization and other things within parts of the program.
  • Ability to preprocess and postprocess the code with the code itself (and each of these can also be preprocessed and postprocessed).
  • BLISS-like assignment and dereferencing.
  • Use statement and expression anywhere, similar to BLISS.
  • BLISS-like structures.
  • Pointers (including function pointers) and types like C, but less confusing and more powerful including with macros.
  • Support for self-modifying codes.
What would your ideal programming language be like ? The original message, this one, and/or others? Or some people just don't intend to make new one anyways.
[url=gopher://zzo38computer.org/].[/url]
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: What would your ideal programming language be like ?

Post by thefox »

mikejmoffitt wrote:I think you might like VHDL - a few of your points (which are things that drive me insane that I don't like at all!) remind me of it.
Or for a more general purpose programming language: Ada. VHDL was based on it.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Re: What would your ideal programming language be like ?

Post by Bregalad »

I use VHDL sometimes at work and I like it, although it's not perfect either. Type conversion is a nightmare, but otherwise I like it more than C (perhaps solely because I use it less).

I'd sure like to learn ADA whenever I'll have the time. It sounds like it is a great language. However I really don't like the fact it was developed by the US army which is probably the reason I didn't learn it yet.

@zzo32 : I am not exactly sure what you have in mind, but it sounds like a language like yours would be awesome. What exactly is BLISS ? Pehaps a few code "samples" of what you have in mind would be cool.

And yes I understand that there is no point in creating new languages anymore which is why I said if one *would* be created. However C although good is horribly flawed.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: What would your ideal programming language be like ?

Post by tepples »

Dismissing a language because of unrelated policies of the organization that created it would be an "Ada hominem".

BLISS, the Basic Language for Implementation of System Software, is what they had before C. The core utilities of VMS were written in BLISS.
Post Reply