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

Started by
63 comments, last by MaulingMonkey 18 years, 5 months ago
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)
DONT LET THEM DISCRIMINATE! BRING BACK THE BLACK!
Advertisement
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?
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.
Variants? Maybe.
Lambdas? Not sure what those are, im thinking there something to do with math/functional programming?

any more ideas? Cmon people! :-p
DONT LET THEM DISCRIMINATE! BRING BACK THE BLACK!
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?
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.
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!
DONT LET THEM DISCRIMINATE! BRING BACK THE BLACK!
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

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
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.

This topic is closed to new replies.

Advertisement