What would your ideal programming language be like ?

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

Moderator: Moderators

WedNESday
Posts: 1231
Joined: Thu Sep 15, 2005 9:23 am
Location: Berlin, Germany
Contact:

Re: What would your ideal programming language be like ?

Post by WedNESday »

I'm gonna create my own programming language, with Blackjack and Hookers. 8-)
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 figured a trick to code in C without the horrible braces using the pre-processor. However, it probably has more drawbacks, for the simple advantage of sometimes avoiding braces.

Advantates :
- Column can be used for FOR instead of semicolun
- Parenthesis for if, else and for compoud statements. No more finger-torturing for europeans who happens to have braces which aren't as accessible as american keyboard

Drawbacks :
- Compiler errors could be more criptic
- Imposibile to use ',' within directly a compoud statement (could be an issue when declaring variables)
- Compoud statements are mandatory (otherwise a normal if/else/for should be used instead)
- Braces STILL have to be used for funtions
- Brackets STILL have to be used for acessing arrays
- Many people will dislike this non-standard way of C coding

Code: Select all

#define IF_SUB(program) {program}
#define IF(condition) if(condition) IF_SUB
#define ELSE(program) else{program}

#define FOR_SUB(program) {program}
#define FOR(init, cond, incr) for(init; cond; incr) FOR_SUB

#include <stdio.h>

// Let's test the above macros
int isprime(int n)
{
	int i;
	IF(n < 3)
	(
		return 1;		// Numbers smaller than 3 are prime
	)
	FOR(i=2, i<=n/2, ++i)
	(
		IF((n%i) == 0)
		(
			return 0;
		)
	)
	return 1;
}

int main()
{
	int i;
	FOR(i=0, i<16, ++i)
	(
		IF(isprime(i))
		(
			printf("%d is prime.\n", i);
		)
		ELSE
		(
			printf("%d is not prime.\n", i);
		)
	)
}
More extreme and simpler is to define BEGIN and END macros for braces, and end up with pascal-style code. I am however not fan of this, "BEGIN" or "END" are as annoying as braces to type if they have to be in caps. In lowercase it could become closer to be a match, but that's encouring the risk of conflicting with the actual code.
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 »

Someone already had this terrible idea 35+ years ago: BSD4.3 sh mac.h, macro.c
Sik
Posts: 1589
Joined: Thu Aug 12, 2010 3:43 am

Re: What would your ideal programming language be like ?

Post by Sik »

Not as bad as CDiv (although to their defense, CDiv was doing some really weird stuff rather than just making alternatives to the syntax).
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 »

And what is CDiv, may I ask ?

And yeah I agree it's not really a good idea to do non-standard stuff like that.
Sik
Posts: 1589
Joined: Thu Aug 12, 2010 3:43 am

Re: What would your ideal programming language be like ?

Post by Sik »

Some attempt to get DIV (a game-centric programming language) style programs on top of C... erm, yeah.
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 »

Now I have another crazy idea. Since you only need variables, ifs and gotos in order to have turning completeness, there is no point in supporting anything else.

But instead of supporting only IFs and GOTOs, I'd rather support only SWITCH statements. Why ? Because switch is definitely more elegant than a long chain of if-elsif-elsif-elsif-else, so even if not technically needed it's a nice ehancement of the "if" that is nice to have built-in the language. A traditional if/else is a switch with only one option and a "default" options, and a if alone is a switch with one option and no "default".

When it comes to loops, they could be simulated with tail recursions into functions that are pre-build in the language, so that when you use them, they appear to be loops. That way, we get loops and don't need the ugly GOTO statement.

So just functions and switch would be enough to build a programming language.

As for types, the more I think about it, the more I belive a programming language without an integer type like I described before is actually not that good of an idea. However, a programming language supporting only integers, and building other types based on integers sounds like a better idea (actually that's why is done in C).
zzo38
Posts: 1080
Joined: Mon Feb 07, 2011 12:46 pm

Re: What would your ideal programming language be like ?

Post by zzo38 »

Bregalad wrote:Now I have another crazy idea. Since you only need variables, ifs and gotos in order to have turning completeness, there is no point in supporting anything else.
Yes, that can be good, and everything else can be done with macros, then.
But instead of supporting only IFs and GOTOs, I'd rather support only SWITCH statements. Why ? Because switch is definitely more elegant than a long chain of if-elsif-elsif-elsif-else, so even if not technically needed it's a nice ehancement of the "if" that is nice to have built-in the language. A traditional if/else is a switch with only one option and a "default" options, and a if alone is a switch with one option and no "default".
Actually I too thought of rather a kind of switch and goto combination as the flow control at the end of a basic block, and then use "register forwarding" between basic blocks; loops (and everything else too, other than some function calls) then basically become a kind of tail recursion just from that.
[url=gopher://zzo38computer.org/].[/url]
Post Reply