Jump to content

Modern Programming Language???

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
valente500

valente500

    Newbie

  • Members
  • Pip
  • 4 posts
Hello. I've been using C++ for about a year now, and now I've gotten to the point where I do not like it anymore (for a number of reasons). Is there a modern programming language similar to C++ that, when compiling, searches through the code once and finds all the class / function declarations, and then compiles so that a class / function can be used before being declared?

For example:
Foo(123,123);

void Foo(int arg1, int arg2)
{
...
}

I would rather a new programming language altogether rather than a workaround sort of thing for C++, since theres other aspects I dislike about it.

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
Have you not heard of function macros or prototypes?

foo(int, int);
foo(123, 210);

void foo(int arg1, int arg2) {
    printf("%d and %d accepted, before declared.", arg1, arg2);
}
From your question I would assume you were not proficient in any one language. You cannot move to a new language that does not reflect or respect the fundamentals of basic programming, they do not exist. And as per your "modern" question, Java is modern, but it is similar for the exact same reason, you will run into the same "problems" as any C varient language.

You may wish to look into using an interpreted language, which would better provide tokenization of classes in your asked requirements.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
artificial

artificial

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 624 posts
Well, I don't know the other reasons why you dislike C++, but maybe C# is what you're looking for.

Greets,
artificial

#4
Milyardo

Milyardo

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
Indeed, prototyping is already a feature of C++. If there are other problems you are having with C++, you should first probably reevaluate your mastery of the language.

#5
valente500

valente500

    Newbie

  • Members
  • Pip
  • 4 posts
I've already heard of function prototyping, what I don't like is that you need to prototype everything in a header before you start writing stuff in source files when you start using multiple files in one program. Maybe I'll try an interpreted language, if not I'll try to fix the problems I'm having.

Thanks for your replies :D

#6
manux

manux

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 234 posts
You don't need to use multiple files, you can just write all the prototypes first in your cpp file (if the functions aren't used elsewhere), if you can't well, 2x the files won't hurt too much :D
If this still bothers to have twice the files, you can see the .h file as the documentation file, it's important not just for the looks and the prototypes, but also to be able to grasp what a module.cpp file does without having to read through the code.

#7
JCoder

JCoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 245 posts
@valente500: I understand you very well. The problem is that the compilation / build system in C++ was taken from 70s (reads: ancient) - they just took the compilation paradigms from C directly, without even thinking that this model was totally irrelevant to OOP. Any modern language doesn't have all these issues - doesn't require you to write stupid prototypes or declare things before they are seen (yes: it is XXI century and multipass / multistage compilers were invented a long time ago), or doesn't base its core features on hacks like dumb text inclusion (pseudo-modules) or text substitution (macros, templates, LOL).

If you want a extremely well thought, multiparadigm, platform independent, modern (first release ca 2005) language, Scala is for you.

#8
abzero

abzero

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 217 posts
From a different view, I like the idea of protoyping. It allows you to think of the interface first, rather than the implementation. Design before code so to speak. Jumping in and hitting the low level straight away isn't always the best idea. It also allows you only to expose the interface part of your code when having api's etc, although that argument is diluted as things like Java are easier to distrubute as an api.

#9
JCoder

JCoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 245 posts
There is no point in writing C style function prototypes, when the language HAS a better builtin feature exactly for this: interfaces (Java) and traits (Scala).

#10
abzero

abzero

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 217 posts
I can't speak for Scala...But java...

What do you mean interfaces are better than a C style function prototype?? An interface is really just a namespaced collection of prototypes (for a single implementation, or an virtual base class for multiple implementations), how is this any better? Not only would you need to define the interface, you'd also need to create another class that matches the interface and then write your code. That's even before we get onto C++ which has support for interfaces, but doesn't define extra keywords just to call them that.

I get that the original poster didn't like defining what he was writing before he wrote it...But, what I was saying is that is bad design, you shouldn't be coding by coincidence, you should think about what you code before you code it.

Now I'm not saying that C++'s build system is the best, It can be a big pain with big complex projects especially when you have certain code modules which start to cross reference. Then your in a world of hurt.

#11
JCoder

JCoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 245 posts

Quote

Not only would you need to define the interface, you'd also need to create another class that matches the interface and then write your code
In C++ you have to do it 3 times:
1. in the header of the "interface"
2. in the header of the implementing class
3. in the definition of the implementing class (and you cannot copy paste the signature - the syntax is slightly different)

And while strict C prototypes really behave like interfaces - they provide code encapsulation, the C++ class headers fail miserably at this - the private section is in the headers. And if you use templates, there is no encapsulation at all - everything is exposed. So, no this is not
as clean as interfaces in Java.

In fact, headers and prototypes were not added to provide interfaces. They just provided a poor-man's method of splitting large project into many files in the world where compilers did not understand the concept of "module".