Valhalla Legends Archive

Programming => General Programming => Topic started by: Banana fanna fo fanna on January 23, 2005, 09:32 PM

Title: The Ultimate Programming Language!
Post by: Banana fanna fo fanna on January 23, 2005, 09:32 PM
Python! No, seriously now, what do you think would comprise the ultimate programming language? I think:

- optional garbage collection which is on by default
- as native as C (none of this VM shit)
- modern language features like packages
- operator overloading with a slew of new operators (like slicing)
- continuations and other LISPy things
- concise, less-typing syntax
- macros
- __maybe__ an intermediate code which can be compiled to native code on various OS's once to generate executabels

I'm asking this because I'm going to write another compiler this semester.
Title: Re: The Ultimate Programming Language!
Post by: tA-Kane on January 24, 2005, 07:18 AM
Disassemblers are more fun to write, let alone a heck of a lot easier, I think.

If you're just writing a compiler, could you not use a language that already exists? Like, write another C compiler?
Title: Re: The Ultimate Programming Language!
Post by: iago on January 24, 2005, 08:31 AM
Quote from: Banana fanna fo fanna on January 23, 2005, 09:32 PM
- concise, less-typing syntax
- macros

Those tend to lead to horrible lazy code.  Macros are the root of many evils, and many hard-to-find problems.  As an example:

#define MAX(a,b) (a<b?b:a)

.......
int c = 4, d = 10;
c = MAX(c++, --d);

Because of the macro expansion, that will expand to:
c = (c++<--d?--d:c++)
Which will, of course, return 8 (because --d is run twice), which is a completely unexpected result.

Anyway, that's my argument against Macros.  Take it how you like :)
Title: Re: The Ultimate Programming Language!
Post by: Arta on January 24, 2005, 09:48 AM
There's nothing wrong with a thoughtful, well-written macro. That macro is stupid. It ought to be a function.

People rail on about macros being bad, but I think that's crap. Macros are an incredibly useful tool. Like anything, they can cause problems when they're misused.
Title: Re: The Ultimate Programming Language!
Post by: Adron on January 24, 2005, 12:50 PM
"garbage collection" and "native" don't go together...
Title: Re: The Ultimate Programming Language!
Post by: Kp on January 24, 2005, 06:01 PM
Actually, you can make a native program which has a garbage collector.  It's just not necessarily going to run as fast as a GC-free language, since the compiler will need to convert all references to complex types into extra record-keeping code to ensure that the reference count is right so it can be garbage collected on schedule.
Title: Re: The Ultimate Programming Language!
Post by: Adron on January 25, 2005, 01:38 AM
But as native as C? You're supposed to be able to cast between numbers and strings and pointers freely, with no type checking, and insert assembler code virtually arbitrarily.... ;)
Title: Re: The Ultimate Programming Language!
Post by: iago on January 25, 2005, 01:41 AM
Quote from: Arta[vL] on January 24, 2005, 09:48 AM
There's nothing wrong with a thoughtful, well-written macro. That macro is stupid. It ought to be a function.

People rail on about macros being bad, but I think that's crap. Macros are an incredibly useful tool. Like anything, they can cause problems when they're misused.

So any macro that uses a variable more than once is "stupid"?  Any macro that uses a variable more than once will succumb to that problem, unless the programmers using the macro are aware that it's a macro and that it might have that effect.
Title: Re: The Ultimate Programming Language!
Post by: Kp on January 25, 2005, 03:27 PM
Quote from: Adron on January 25, 2005, 01:38 AMBut as native as C? You're supposed to be able to cast between numbers and strings and pointers freely, with no type checking, and insert assembler code virtually arbitrarily.... ;)

I see your point.  From his statement of "as native as C (none of this VM shit)", I took it merely to mean that he wanted processor-native code, as opposed to interpreted bytecode.  It would complexify the language a bit (and introduce extra work for programmers who wanted to do casting), but I still think he could make a machine-native garbage collector.  It'd merely require a convention such as "You must keep a visible reference to an object or it'll go away, even if your inlined assembly still knows about it" for garbage-collected objects.  He already specified that garbage collection would be optional, so arbitrarily crafted pointers would be declared as not-garbage-collected.
Title: Re: The Ultimate Programming Language!
Post by: Banana fanna fo fanna on January 25, 2005, 03:59 PM
I was thinking something along the lines of:


class MyClass extends GarbageCollected {
   ...
}
Title: Re: The Ultimate Programming Language!
Post by: dxoigmn on January 25, 2005, 04:23 PM
Quote from: Banana fanna fo fanna on January 25, 2005, 03:59 PM
I was thinking something along the lines of:


class MyClass extends GarbageCollected {
   ...
}


Then you need to implement multiple inheritance which is icky.
Title: Re: The Ultimate Programming Language!
Post by: Adron on January 25, 2005, 04:40 PM
But if all you're doing is create a class to inherit from to get garbage collection, you might as well use C++ and write a garbage collector for it, or use one of the existing ones ;)
Title: Re: The Ultimate Programming Language!
Post by: tA-Kane on January 25, 2005, 04:48 PM
That wouldn't be a bad idea of garbage collection wasn't a bad idea in the first place.

Nothing like keeping track of your garbage yourself... :P
Title: Re: The Ultimate Programming Language!
Post by: dxoigmn on January 25, 2005, 05:52 PM
Quote from: tA-Kane on January 25, 2005, 04:48 PM
That wouldn't be a bad idea of garbage collection wasn't a bad idea in the first place.

Nothing like keeping track of your garbage yourself... :P

Garbage collection is the best.
Title: Re: The Ultimate Programming Language!
Post by: tA-Kane on January 25, 2005, 07:53 PM
Btw, I think having all user variables *not* stored on the stack may be a good idea for a language... especially not arrays...
Title: Re: The Ultimate Programming Language!
Post by: Banana fanna fo fanna on January 25, 2005, 09:52 PM
Quote from: dxoigmn on January 25, 2005, 04:23 PM
Quote from: Banana fanna fo fanna on January 25, 2005, 03:59 PM
I was thinking something along the lines of:


class MyClass extends GarbageCollected {
...
}


Then you need to implement multiple inheritance which is icky.

Not if it's done right.
Title: Re: The Ultimate Programming Language!
Post by: Kp on January 26, 2005, 09:47 AM
Quote from: tA-Kane on January 25, 2005, 07:53 PMBtw, I think having all user variables *not* stored on the stack may be a good idea for a language... especially not arrays...

Why?  Extremely short life arrays are much better on the stack, and if you're concerned about buffer overflows then:

1) You need a better programmer.
2) You could design the language to automatically check all load/stores to some/all arrays and abort on overflow.  This is a performance hit, and it's not backward compatible with some C wizardry, so it isn't done in C/C++.  Java does it, which is one reason it's such a nuisance to be clever with pointers.
Title: Re: The Ultimate Programming Language!
Post by: MyndFyre on January 26, 2005, 10:29 AM
Quote from: Banana fanna fo fanna on January 25, 2005, 09:52 PM
Quote from: dxoigmn on January 25, 2005, 04:23 PM
Quote from: Banana fanna fo fanna on January 25, 2005, 03:59 PM
I was thinking something along the lines of:


class MyClass extends GarbageCollected {
...
}


Then you need to implement multiple inheritance which is icky.

Not if it's done right.

For example, instead of "extends", try "implements".  Interfaces are a good thing.  ;)
Title: Re: The Ultimate Programming Language!
Post by: Banana fanna fo fanna on January 26, 2005, 08:07 PM
Ah...how about automatic boundschecked arrays?
Title: Re: The Ultimate Programming Language!
Post by: Kp on January 26, 2005, 09:53 PM
Quote from: Banana fanna fo fanna on January 26, 2005, 08:07 PMAh...how about automatic boundschecked arrays?

Isn't that what I said? :)  Anyway, I'd suggest making that optional too (but maybe default to on).  I've occasionally found use for using "zero-length" arrays to alias other data types (especially variable length data that immediately follows a structure in memory), and bounds checking would ruin that.