Sign in to follow this  
Falling Sky

Things you could modify about C/C++/C#

Recommended Posts

Sup guys, im doing a bit of research & was going to implement my own variation of a C language as my school project. Im just curious, if you could do whatever you wanted to a form of C, what would you modify about it? And since im also interested in games I wanted to supply a simple game, such as pong, as an example program made in my compiler. So please tell me your ideas to modify C/C++/C#(keep the idea in mind that if its more geared for games, thats great, that would give it some unique features to be geared for media)

Share this post


Link to post
Share on other sites
I would add a feature to let you reduce this:

ClassA *a = dynamic_cast<ClassA*>(object);
if (a != NULL)
{

}
else
{
ClassB *b = dynamic_cast<ClassB*>(object);
if (b != NULL)
{
...
}
}


into something like this:


dynamicswitch (object)
{
typecase ClassA(a)
{
a->function1();
} // implied break. user cannot create fall-throughs or goto a different typecase.

typecase ClassB(b)
{
b->function2();
}
}


Sure, there are invasive ways to add this to existing classes so that you can switch on a member variable defined in the base class, but why waste space when you probably have a vtable pointer anyway?

Share this post


Link to post
Share on other sites
Quote:
Original post by Nypyren
I would add a feature to let you reduce this:

ClassA *a = dynamic_cast<ClassA*>(object);
if (a != NULL)
{

}
else
{
ClassB *b = dynamic_cast<ClassB*>(object);
if (b != NULL)
{
...
}
}


into something like this:


dynamicswitch (object)
{
typecase ClassA(a)
{
a->function1();
} // implied break. user cannot create fall-throughs or goto a different typecase.

typecase ClassB(b)
{
b->function2();
}
}


Sure, there are invasive ways to add this to existing classes so that you can switch on a member variable defined in the base class, but why waste space when you probably have a vtable pointer anyway?


I like that (similar to pattern matching in languages like Ocaml and Haskell). Although, personally, I'd get rid of the typecases and change dynamicswitch to match.

Some other features you might want to think about are variant types (these work well with the feature Nypyren mentioned), coroutines and lambdas.

Share this post


Link to post
Share on other sites
Quote:
Original post by Azh321
Variants? Maybe.
Lambdas? Not sure what those are, im thinking there something to do with math/functional programming?

any more ideas? Cmon people! :-p


Lambdas are nameless functions. How about coroutines and/or continuations?

Share this post


Link to post
Share on other sites
Native regular expression goodness. C# might actually have that [I've no idea], and it can be added to c/c++, but it always seems so icky and contrived compared to something like perl's.

Share this post


Link to post
Share on other sites
I dont see much purpose in nameless functions or coroutines. I will probaly do variants though, cmon guys tell me what you really like about C# that you wish C++ had, tell me what you wish C++ had/didnt have!

Share this post


Link to post
Share on other sites
One example of where coroutines are useful are infinte lazy lists. Lambdas are useful for creating functions to pass to other functions (in some cases). For instance (using a hypothetical syntax):

map((\(int x) -> int { return x + 1; }), {1, 2, 3, 4}) // Returns {2, 3, 4, 5}


Here are a few more things you might want to consider:

  • Metaclasses

  • Continuations

  • Type inferred generics

  • Tail-recursion optimization (this isn't a language thing, although it's something to think about when implementing the compiler)

  • A nicer looking function pointer syntax

  • Templated typedefs

  • Closures and inner functions

  • Optional lazy evaluation

Share this post


Link to post
Share on other sites
Have you taken a look at Objective-C?

I would want to make changes directly to C because I think that C++ has too many features. The features that I would add to C are:

1. Classes
2. Inheritance
3. Interfaces
4. Optional Automatic Garbage Collection
5. Interpreter and compiler
6. Standard Graphics API based on OpenGL
7. Change primitives to int8, int16, int32, int64, int128, float32, float64, float128, boolean, char, and void
8. Clean import utility for importing classes and functions

I would remove:

1. Preprocessor - nothing but nightmares

Share this post


Link to post
Share on other sites
Quote:
Original post by AllTheLuck
1. Preprocessor - nothing but nightmares


Preprocessors aren't inherently bad, although (in my opinion) C implemented it badly. See hygienic macros.

Share this post


Link to post
Share on other sites
auto variable declarations1, and anonymous functions. I don't care so much about proper lambdas, I just want to use for_each without jumping through hoops. And yes, for any non-trivial cases boost::lambda is jumping through hoops.

That's really it. I suspect that neither of those would be terribly useful in C, and I don't know enough C# to comment.

AllTheLuck: (1) through (4) go a long way towards making C into C++, which I'm sure we can all agree is not a good idea. (5) is not a language feature, whatever Java and C# would have you believe. (6) is completely retarded, and (7) is half-way provided already [no floating point types, and no 128-bit integer support out of the box].

CM

1 *edit: Just so there is no confusion, I'm refering to real, strong type declarations that the compiler implies on its own, not some sort of variant type like those found in VB and a few other languages.

Share this post


Link to post
Share on other sites
Quote:
Original post by AllTheLuck
6. Standard Graphics API based on OpenGL


I've heard of this. You can get it as a library for C or C++, as well as a few other languages. It's really quite popular, you should check it out. I froget the exact name though... OpenLG? GLOpen? GOpenL?

My list is along the linse of:

1) Templated typedefs.
2) auto (same one as Conner McCloud)
3) Multiple Dispatch.

Much more than that and you're looking at a new language. Which is not something I'm opposed to I might add, it's just that such a system would be better built without the C/C++ heritage of mistakes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Azh321
I dont see much purpose in nameless functions or coroutines. I will probaly do variants though, cmon guys tell me what you really like about C# that you wish C++ had, tell me what you wish C++ had/didnt have!


Properties(get/set) that doesn't interfer with functions

a for_each clasue

dot for accesing classes/variables/names in the namespace

New stuff:
syntax, easy enough so it is easy to convert existing C/C++ code to the new one. perhaps providing a converter ;)

the function returning for than one value

the abiliy to define other operators than the standard operators

sending the compiler a file that tells how to handle the text-input(essential a lexer). Could be a simple as banning different names in different contexts(like a class must have a large letter and no underscore, and constants should be written with only large letters), or as complex and let the user define what an if looks like(perhaps If or something in there language - to help newbies?).

preprocessor type checking, like

/*
The main difference between a stament and a value is that
the value can be assigned, the statement can not
*/


// statement is a executing statement, like print("") or perhaps i = 2
macro: statement myMacro(bool val, statement a, statement b) {
if( val ) {
val = false;
return a;
}
else {
return b;
}
}

// now the statement represents a float, like 5.0f+2.0f, or sqrt(9.0f)
macro: statement<float> myMacro(bool val, statement<float> a, statement<float> b) {
if( val ) {
return a;
}
else {
return b;
}
}

// useless function, but you get the point ;)
void useMacro(bool val, float& of) {
macro:myMacro( val, print("hello"), of=2.0f );
of += macro:myMacro( val, sqtr(of), log(of) );
}


This may be related to hygienic macros. I understood nada of those scheme-pages that I got from google.

Share this post


Link to post
Share on other sites
Tuples. Not as a data type, but as a form of expression. For example

float, float GetXY() // tuple return type
{
return 4.0, 7.3;
}
int main()
{
float x, y;
x, y = GetXY(); // tuple assignment
return 0;
}


Anonymous functions just like those in Lua would be a huge improvement to any language.

ISO C99-style structure initialisers.

No more need for forward declarations. Members of a class can be used before they are defined, so why not extend this to an entire file?

Be able to declare inheritance when declaring classes (not just when defining them). For example

class class1 {public: class1(){} float a;};
class class2 {public: class2(){} float b;};

class class 3: public class1, public class2; // class3 is defined elsewhere


Ability to make members of a class private, but visible publicly as const.

class MyClass
{
public:
MyClass();
private public const:
float a;
};

Share this post


Link to post
Share on other sites
Hello,

I have a couple of remarks about what has already been said.

Quote:
Original post by Nypyren
I would add a feature to let you reduce this:

(snip stuff about synamic_cast<> and dynamicswitch)

Sure, there are invasive ways to add this to existing classes so that you can switch on a member variable defined in the base class, but why waste space when you probably have a vtable pointer anyway?


That's a clever way to break one of the most important OOP design principle - the "open Closed Principle". As a consequence, it also provide a cool way to break the "Liskov Substitution Principle". Code like this should not exist because it cannot be extended without modification. The correct way to implement this is to create a virtual function in the base class and to override this function definition in ClassA and ClassB. Thus, I think that adding this functionnality to the language is not really a good idea.

One thing I'd find cool in a C++ compiler is type-safe enumerations. I'm not sure about that auto keyword - in fact, I fear badly writtent code that will use auto everywhere - thus making the code barely readable (no, you don't have to know what is the type of this variable. It is auto).

Quote:
Original post by sirGustav
the function returning for than one value

I can't see how you can implement this. there is no real advantages in

return (x, y);

You can already write this in C++

return point(x, y);

Not to mention that the calling code would be weird :)

Quote:
[i]Original post by Saruman[i]
Definately a nice native interface for properties in C++ as said above.

Thirded. An interface or a code construction to create properties would be a nice thing, as well as a mecanism to enumerate these properties at run time.

Another possible area of improvement is definitely the libraries that would come with such language.

Default (2/3/4)D matrix, (2/3/4)D vector types would also be nice (the code generated by the compiler would take advantage of this).

Regards,

Share this post


Link to post
Share on other sites
>float, float GetXY() // tuple return type
pair<float,float> getXY()

>inner functions
Is possible, however with a little trickery (put
the function inside a union)

>6. Standard Graphics API based on OpenGL
For this, you have api's - that's definately sth which does
NOT belong in the language, just like audio, moviedisplay and
(de)compression of mp3's aren't part of the language.

Some additional "base" libraries - not as a part of the language! -
(like eg the stl) for matrices, compression/decompression and other
areas would be interesting (as long as it's standardized)

>Sure, there are invasive ways to add this to existing classes so that you can
>switch on a member variable defined in the base class, but why waste space
>when you probably have a vtable pointer anyway?
I agree with Emmanuel Deloget :)

Support for sth like "enum_as_string" would be nice though :)

[Edited by - Kitt3n on November 11, 2005 7:59:59 AM]

Share this post


Link to post
Share on other sites
I think that I should better explain what I meant earlier by a standard graphics API based on OpenGL. What I mean is to include a small subset of OpenGL into standard C so that on any device those libraries can be expected.

In some embedded systems it would be a waste to have this extra functionality, but for most systems it would be very nice. Graphical User Interfaces could be defined based on the small set of drawing functions as well as 3D applications. This would be very nice from a portability standpoint.

The reason that I would actually like it to be part of the language standard so that people would feel obligated to use it or that it would be the obvious choice.

I hope that this makes it more clear.

Share this post


Link to post
Share on other sites
Quote:
Original post by AllTheLuck
I think that I should better explain what I meant earlier by a standard graphics API based on OpenGL. What I mean is to include a small subset of OpenGL into standard C so that on any device those libraries can be expected.

In some embedded systems it would be a waste to have this extra functionality, but for most systems it would be very nice. Graphical User Interfaces could be defined based on the small set of drawing functions as well as 3D applications. This would be very nice from a portability standpoint.

The reason that I would actually like it to be part of the language standard so that people would feel obligated to use it or that it would be the obvious choice.

I hope that this makes it more clear.

It was perfectly clear before. Just completely retarded. Why should the language dictate what features the environment has? Why should people feel compelled to use OpenGL? What use does a low level language like C have for a high level construct like a graphical library? Why should a rapidly evolving field like graphic libraries be stripped down and locked into a single static version for the rest of time? And so forth.

CM

Share this post


Link to post
Share on other sites
1)A read-only attribute (oh that's for C++ not C).
2)<<< & >>> operators.
3)Returning tuples. I use a language at work that allows this and I have seen a variant of C++ before that did it. Must be an easy thing to do.
4)multiple levels of /* & */ so you can have nested comment blocks.
5)Fix scope when you do (for int i=....) and then i exists outside the for loop.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Conner McCloud
auto variable declarations[...]
C++ already has 'auto' =-P
I think there is a good reason for a typeof() operator though, that evaluates to the type of the result of the passed expression (which can contain variables and types both, for ex typeof(5+10) might be int, int a, b; typeof(a + b) might be int, and typeof(int+int) might be int). This would make templates much more powerful, because it eliminates the need to assume that T+T is also of type T when it could be any type, but it adheres more to the principle of strong static typing than an 'autotype' keyword would. It also allows a one-pass compiler, while 'autotype' would make one-pass compiling much more difficult and thus compiling would be slower.
-Extrarius

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Conner McCloud
auto variable declarations[...]
C++ already has 'auto' =-P
I think there is a good reason for a typeof() operator though, that evaluates to the type of the result of the passed expression (which can contain variables and types both, for ex typeof(5+10) might be int, int a, b; typeof(a + b) might be int, and typeof(int+int) might be int). This would make templates much more powerful, because it eliminates the need to assume that T+T is also of type T when it could be any type, but it adheres more to the principle of strong static typing than an 'autotype' keyword would. It also allows a one-pass compiler, while 'autotype' would make one-pass compiling much more difficult and thus compiling would be slower.
-Extrarius

Share this post


Link to post
Share on other sites
We get a thread like this every couple of months. C++ must be doing something right if so many people want to change it, but keep using it anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by Conner McCloud
auto variable declarations1, and anonymous functions. I don't care so much about proper lambdas, I just want to use for_each without jumping through hoops. And yes, for any non-trivial cases boost::lambda is jumping through hoops.

That's really it. I suspect that neither of those would be terribly useful in C, and I don't know enough C# to comment.

C# 2.0 already has anonymous functions, C# 3.0 will have a more lambda-like syntax for anon functions plus a var keyword that does what you describe; infer actual type from the RHS.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this