473,385 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C++ without forward declarations?


Will C++ ever have Java-like multiple level compiling?

So that we can dump the old model of having to first declare then write
the code?

I find the declaration wastes so much time in coding. It's little more
than something needed for the preprocessor, apart from that it is
ancient junk. It's not needed in Java or other modern OOP languages
(Visual Basic and REALbasic), so why C++?

That's gotta be my biggest gripe with C++. The rest are just stuff I
can live with.

It would be nice if objects had a standardised implementation, also.
Some standard function we could call to get at it's class. Inbuilt
introspection, basically. Java's got introspection... I suppose you can
introspect in C++ if you are willing to do bad things to the memory and
read pointers beyond the class's bounds.

Dec 23 '06 #1
10 1620
Actually, now that I think about it... C++'s & keyword really sucks.

It's like a crippled pointer. You can't "Reseat" it like you can in
Java :(

It's just for syntactic sugar, and it still manages to be wrong!!! Why
not just extend "." (dot) to just work with pointers or references?
That would be more like Java and better.

And also, why should we even need to define something as virtual or
not? Shouldn't the compiler know if you've subclasssed a function or
not? This virtual keyword is useless, harmful and annoying.

Why doesn't the compiler also ask me to tell it what registers to stuff
the params in? And if I don't know, it throws an error because it
secretly knew the answer already?

What a stupid system, to ask the programmer to tell the compiler
something it already knows, just so it can waste his time!!! Really
stupidity. If I were the designer of C++ I'd kill the 'virtual'
keyword.

Also, putting functions into the class shouldn't really inline it...
The "inline" keyword should do that. We already have an inline keyword
so why imply that putting it in the class does the same???? It's
redundant. The more ways you have to do the same thing the more bloated
a language becomes :(

Also, shared pointers (like what boost has got), should have been in
C++ by default, even if in the stl. And they should have been promoted
as more important to use than new/delete. new/delete are such overused
concepts, I really do my best to avoid them, but all too often I come
across libraries written by other people using them when they could
have used STL's string or container classes instead. It's annoying.

I think it should be easier to use a shared pointer than it is to do
new/delete. That would be an "implicit" recommendation to do it a
certain way. If you make one technique easier, you are basically
recommending it even if you haven't said "go down this path".

And it shouldn't be possible to use templates on templates, unless they
are typedeffed first :( Template madness really hurts the eyes.

And C++ should have specified some standardised name mangling. Because
linking C++ libraries is impossible due to Bjorne's oversight here. He
should have seen this one ahead of time... Also, the 'this' keyword
should always be the first parameter in terms of the actual stuff going
on in the registers.

Dec 24 '06 #2
co**********@googlemail.com wrote:
Actually, now that I think about it... C++'s & keyword really sucks.

It's like a crippled pointer. You can't "Reseat" it like you can in
Java :(
This is actually why it is good.

It's just for syntactic sugar, and it still manages to be wrong!!!
It's not just syntactic sugar.
And I hardly see how it's wrong.

Why
not just extend "." (dot) to just work with pointers or references?
Because pointers are not objects, but pointers to objects.

That would be more like Java and better.
C++ doesn't aim to be like Java.

>
And also, why should we even need to define something as virtual or
not? Shouldn't the compiler know if you've subclasssed a function or
not?
First, the compiler can't know.
Second, you might want to not use virtual, even when subclassing.

This virtual keyword is useless, harmful and annoying.
It is here to provide polymorphism for those that want it.
What a stupid system, to ask the programmer to tell the compiler
something it already knows, just so it can waste his time!!! Really
stupidity. If I were the designer of C++ I'd kill the 'virtual'
keyword.
The job of a compiler isn't to guess your errors and correct them
automagically.
When errors occur, it tells you what those errors are. It can try to
guess what you did wrong, but that's it.

Also, putting functions into the class shouldn't really inline it...
It doesn't.
It is just a precondition.

The "inline" keyword should do that.
It doesn't either, it's just an advice.

Also, shared pointers (like what boost has got), should have been in
C++ by default, even if in the stl. And they should have been promoted
as more important to use than new/delete.
shared pointers are also overused.
Normally you shouldn't need to use them at all, unless you want to share
data.

new/delete are such overused
concepts, I really do my best to avoid them
Of course you should *never* use them unwrapped, that would cause
obvious exception safety problems.

>, but all too often I come
across libraries written by other people using them when they could
have used STL's string or container classes instead. It's annoying.
Unfortunetely, most existing C++ code is bad, mainly because people
believe C++ is C with classes.
There is nothing the C++ language can do about it.

I think it should be easier to use a shared pointer than it is to do
new/delete. That would be an "implicit" recommendation to do it a
certain way.
An implicit recommendation is to favorize allocation on automatic memory
rather than dynamic memory allocation.
And it shouldn't be possible to use templates on templates, unless they
are typedeffed first :( Template madness really hurts the eyes.
That's a stupid idea.

And C++ should have specified some standardised name mangling. Because
linking C++ libraries is impossible due to Bjorne's oversight here. He
should have seen this one ahead of time...
It's possible.
Also, the 'this' keyword
should always be the first parameter in terms of the actual stuff going
on in the registers.
What are you talking about?
Dec 24 '06 #3
co**********@googlemail.com wrote:
Actually, now that I think about it... C++'s & keyword really sucks.

It's like a crippled pointer. You can't "Reseat" it like you can in
Java :(

It's just for syntactic sugar, and it still manages to be wrong!!! Why
not just extend "." (dot) to just work with pointers or references?
That would be more like Java and better.
I'm not sure what your problem is. Please give concrete examples of
what you'd like to do bearing in mind that C++'s goals, that incidently
were very different to that of Java.
>
And also, why should we even need to define something as virtual or
not? Shouldn't the compiler know if you've subclasssed a function or
not? This virtual keyword is useless, harmful and annoying.
That's a great question. Both are useful. In C++ you can have both.
>
Why doesn't the compiler also ask me to tell it what registers to stuff
the params in? And if I don't know, it throws an error because it
secretly knew the answer already?
What are you talking about ? The "register" keyword serves a far
different purpose today than it did when compilers were less capable.
Today, the only thing you can count on is that a variable marked as a
register cannot have it's address taken at most giving the optimizer a
hint that the object is not aliased.
>
What a stupid system, to ask the programmer to tell the compiler
something it already knows, just so it can waste his time!!! Really
stupidity. If I were the designer of C++ I'd kill the 'virtual'
keyword.
That's nice, you're too late. You should have been around 20 years ago
when the discussions about C++ were evolving.
>
Also, putting functions into the class shouldn't really inline it...
The "inline" keyword should do that. We already have an inline keyword
so why imply that putting it in the class does the same???? It's
redundant. The more ways you have to do the same thing the more bloated
a language becomes :(
The meaning of "inline" and the compiler's choice to actually inline are
two very different things. You should file bugs with the compiler
vendor if you have a problem, you'll find they're very responsive.
>
Also, shared pointers (like what boost has got), should have been in
C++ by default, even if in the stl. And they should have been promoted
as more important to use than new/delete. new/delete are such overused
concepts, I really do my best to avoid them, but all too often I come
across libraries written by other people using them when they could
have used STL's string or container classes instead. It's annoying.
Smart pointers are relatively new. Compilers only until recently (last
6 years or so) were too buggy. You also have the option of using a
garbage collector -like in Java.
>
I think it should be easier to use a shared pointer than it is to do
new/delete. That would be an "implicit" recommendation to do it a
certain way. If you make one technique easier, you are basically
recommending it even if you haven't said "go down this path".
No argument. Personally, I don't like boost's shared_ptr, I prever
intrusive reference counts since they cause (imho) less issues.
>
And it shouldn't be possible to use templates on templates, unless they
are typedeffed first :( Template madness really hurts the eyes.
Ah - welcome to the world of programming the compiler. Templates are an
extremely powerful concept but it does need the user to think very very
differently about programming.
>
And C++ should have specified some standardised name mangling. Because
linking C++ libraries is impossible due to Bjorne's oversight here. He
should have seen this one ahead of time...
Not at all. There are other much easier ways to do these things that
require no knowledge of name mangling. If you look at the Austria C++
generic factory implementation. It works with dynamically linked
libraries and with absolutely no knowledge of name mangling.

.... Also, the 'this' keyword
should always be the first parameter in terms of the actual stuff going
on in the registers.
Why do you care?

C++ certainly has a number of warts, but it is a far more powerful
language than C. I have not followed JAVA recently, but in my opinion
it has much more flexibility than Java as well but that does mean you
need to put in the time to know the language. When I started messing
with C++ there were very few examples of good uses of C++ so the
learning curve was a bit longer, now that has changed, there are many
good examples of C++ applications that are very very good. The
compilers have only recently (last 2 years) caught up with the standard.

My advice to you is, don't expect C++ to be perfect, it is what it is
and the quicker you learn what it is and stop being frustrated, the
quicker you'll be up the learning curve and useful. Bitching about it
isn't going to help.

As for the perfect langauge, don't hold your breath, if C++/Java etc are
any indication, it will take a long time to get here so you had better
learn to use the tools you have. Still, that should not preclude you
from dreaming about what the perfect language looks like, just don't
expect it to appear unless you're willing to put in some serious energy.

Dec 24 '06 #4
mpa

co**********@googlemail.com wrote:
What a stupid system, to ask the programmer to tell the compiler
something it already knows, just so it can waste his time!!! Really
stupidity. If I were the designer of C++ I'd kill the 'virtual'
keyword.
http://www.cryptonomicon.com/beginning.html

That link points to an essay which everybody who doesn't understand the
essential differences between languages like Java and languages like
C++ should read.

In brief, it explains why professionals use power tools which can kill
people, and why amateurs use safe, heavily-regulated tools that aren't
the least bit dangerous -- but also can't do as much useful work.

It may also be useful to remember that without danger, there is no
romance.

--mpa

Dec 24 '06 #5

co**********@googlemail.com wrote:
Actually, now that I think about it... C++'s & keyword really sucks.

It's like a crippled pointer. You can't "Reseat" it like you can in
Java :(
A reference in Java is not a reference, its a raw pointer. C++'s
reference is not reseatable because thats its purpose. Sorry, Java has
no such thing. C++ references are a Godsend.
C++ also has ways to make a pointer unseatable: int* const p (its so
nice to have choice).
>
It's just for syntactic sugar, and it still manages to be wrong!!! Why
not just extend "." (dot) to just work with pointers or references?
That would be more like Java and better.
No, it would be uglier. In Java, you don't know if its a pointer or an
instance.
>
And also, why should we even need to define something as virtual or
not? Shouldn't the compiler know if you've subclasssed a function or
not? This virtual keyword is useless, harmful and annoying.

Why doesn't the compiler also ask me to tell it what registers to stuff
the params in? And if I don't know, it throws an error because it
secretly knew the answer already?

What a stupid system, to ask the programmer to tell the compiler
something it already knows, just so it can waste his time!!! Really
stupidity. If I were the designer of C++ I'd kill the 'virtual'
keyword.
Thats a silly comment. You are suggesting that all member functions
should be virtual. What if a member function needs not be virtual? And
most don't. What if you need a static function? What if you need a
pure-virtual member function that is defined? Java does not even allow
that.
>
Also, putting functions into the class shouldn't really inline it...
The "inline" keyword should do that. We already have an inline keyword
so why imply that putting it in the class does the same???? It's
redundant. The more ways you have to do the same thing the more bloated
a language becomes :(
Inline is a suggestion, whether the function is defined in the
declaration is irrelevant.
Bloated? Here's bloated:
a non-optional GC, a non-optional virtual machine, a ctor that does not
support init lists, etc...
It doesn't get more bloated than that.
>
Also, shared pointers (like what boost has got), should have been in
C++ by default, even if in the stl. And they should have been promoted
as more important to use than new/delete. new/delete are such overused
concepts, I really do my best to avoid them, but all too often I come
across libraries written by other people using them when they could
have used STL's string or container classes instead. It's annoying.

I think it should be easier to use a shared pointer than it is to do
new/delete. That would be an "implicit" recommendation to do it a
certain way. If you make one technique easier, you are basically
recommending it even if you haven't said "go down this path".
Actually, better than new/delete and better than smart pointers is
using the stack, whenever possible. Gee, does Java have a stack? Yes,
for primitives only, lol.
>
And it shouldn't be possible to use templates on templates, unless they
are typedeffed first :( Template madness really hurts the eyes.
Really. In Java everything is a template. And worst still - everything
is a template based on Object.
Do you know how many programmers walk in here every week having to
unlearn that sick, bad, demented, ill-conceived and innappropriate way
to code?
In C++, templates are optional, programeable as well as inheritable.
And they are so simple to use. Complete with type-checking help from
the compiler.
>
And C++ should have specified some standardised name mangling. Because
linking C++ libraries is impossible due to Bjorne's oversight here. He
should have seen this one ahead of time... Also, the 'this' keyword
should always be the first parameter in terms of the actual stuff going
on in the registers.
Namespaces resolve the naming issue. Consider that C++ has a long
history and a need to keep some level of backward compatibility as well
as forward momemtum. Its far from being perfect, buts its done a superb
job so far.

And if you think Java is perfect, then go on, beleive it.

Dec 24 '06 #6
I normally don't respond to trolls, but it's the holidays, so... just this
once...

co**********@googlemail.com spewed garbage all over the newsgroup:
It's like a crippled pointer.
Not quite. You're welcome not to use it if you don't like it.

You can't "Reseat" it like you can in Java :(
Oh. Boo hoo. It's not like Java... *cries*

It's just for syntactic sugar, and it still manages to be wrong!!!
It's not just syntactic sugar. As for it being 'wrong' do tell us, how is it
wrong exactly?

Why
not just extend "." (dot) to just work with pointers or references?
That would be more like Java and better.
Making a single operator work on both pointers and references, hiding the
differences between the two *IS* syntactic sugar. What you just griped against.

As for your "just like Java" = "better" comment, that has got to be the
_dumbest_ thing that I have _ever_ heard.

And also, why should we even need to define something as virtual or
not? Shouldn't the compiler know if you've subclasssed a function or
not? This virtual keyword is useless, harmful and annoying.
So you don't have to worry about the overhead of 'virtual' when you don't
need it while still being able to get its benefits when you do.

What a stupid system, to ask the programmer to tell the compiler
something it already knows, just so it can waste his time!!! Really
stupidity. If I were the designer of C++ I'd kill the 'virtual'
keyword.
Just because _you_ don't understand what purpose something serves doesn't
make it stupid. Making grandiose statements about things you don't understand,
however, serves only one purpose: to advertise to everybody just _how_ stupid
you are.

Also, putting functions into the class shouldn't really inline it...
It doesn't. The compiler is free to consider inlining it regardless of where
it is.

The "inline" keyword should do that.
You do understand that 'inline' is just a hint and not a guarantee, right?

I think it should be easier to use a shared pointer than it is to do
new/delete. That would be an "implicit" recommendation to do it a
certain way. If you make one technique easier, you are basically
recommending it even if you haven't said "go down this path".
Yeah, and why don't we do away with new/delete altogether, and blah blah
blah... Oh wait... if you want Java, there's a perfect language for you. It's
called (*drumroll*) Java!

And it shouldn't be possible to use templates on templates, unless they
are typedeffed first :( Template madness really hurts the eyes.
You are, of course, welcome to do that with your own code, to avoid hurting
your beady eyes. But unless you have good _technical_ reasons for what you're
suggesting, take it elsewhere.

And C++ should have specified some standardised name mangling. Because
linking C++ libraries is impossible due to Bjorne's oversight here. He
should have seen this one ahead of time...
Having standardised name-manging is the last thing you need to worry about
for cross-linking stuff from compiler A and compiler B. You have much more
important problems to worry about. I bet that's Bjarne's fault too!

Also, the 'this' keyword
should always be the first parameter in terms of the actual stuff going
on in the registers.
What are you talking about? Registers? C++ knows nothing of registers. How
arguments are passed in between functions is something that is specific to a
particular platform.

-n
Dec 24 '06 #7
co**********@googlemail.com wrote:
Actually, now that I think about it... C++'s & keyword really sucks.

It's like a crippled pointer. You can't "Reseat" it like you can in
Java :(

It's just for syntactic sugar, and it still manages to be wrong!!! Why
not just extend "." (dot) to just work with pointers or references?
That would be more like Java and better.

And also, why should we even need to define something as virtual or
not? Shouldn't the compiler know if you've subclasssed a function or
not? This virtual keyword is useless, harmful and annoying.

What a stupid system, to ask the programmer to tell the compiler
something it already knows, just so it can waste his time!!! Really
stupidity. If I were the designer of C++ I'd kill the 'virtual'
keyword.
You should temper your expectations with a dose of realism. A C++
compiler has its hands full coping with naming scopes, deducing
template type arguments and verifying that each source file ends with a
new line - in other words, the stuff that matters. So there are simply
no cycles left over for the types of frivolous luxuries that you are
demanding - or anything else that would make programming in C++ more
convenient for the programmer. It's not a priority of the language, and
it should not be one of your priorities either.

I'm a bit suprised you forgot to mention the preprocessor - C++'s
ace-in-the-hole, a nearly ironclad insurance policy against any kind of
decadent feature (such as automatic "refactoring") available in other
languages, from ever spoiling C++ programmers with its usefulness.
Also, putting functions into the class shouldn't really inline it...
The "inline" keyword should do that. We already have an inline keyword
so why imply that putting it in the class does the same???? It's
redundant. The more ways you have to do the same thing the more bloated
a language becomes :(
The usual response is that the compiler is going to do whatever it
wants so to do anyway, so "inline" exists just to support the fiction
that you have some say in the decision.

Greg

Dec 24 '06 #8


On Dec 24, 12:02 am, collectio...@googlemail.com wrote:
Actually, now that I think about it... C++'s & keyword really sucks.

It's like a crippled pointer. You can't "Reseat" it like you can in
Java :(
Just to be clear...

Java's References are nothing like C++ references - the only similarity
is the name. If anything, Java References are closest to C++ pointers,
the only exception being you can't do pointer arithmetic with Java's.

Java References are essentially pointers to Java Objects.

....so you have them already in C++
snipped

Andrew

Dec 24 '06 #9
mpa wrote:
In brief, it explains why professionals use power tools which can kill
people, and why amateurs use safe, heavily-regulated tools that aren't
the least bit dangerous -- but also can't do as much useful work.

C++ isn't really dangerous.
Dec 24 '06 #10
co**********@googlemail.com wrote:
>
Will C++ ever have Java-like multiple level compiling?
Another whiny jackass to plonk.

Brian

Dec 25 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mjm | last post by:
Folks, Please help me with the following problems: ******************************************** 1. I have a class template template<class Base> class Matrix : public Base { /* .... */ }
10
by: Alan Lee | last post by:
Hi i am writing a small simulation for a bunch of atoms jumping around on a surface. I know i am a crappy programmer since i am not very familiar with object oriented languages. I am woindering...
5
by: John Gabriele | last post by:
I'm hoping someone can please help me remember the C++ rule: When you're writing a header file for a class (say, some_namespace::Bar), and that class makes use of another class...
11
by: aleko | last post by:
This applies equally to function prototypes. Why do we have to tell the compiler twice? Other modern compiled languages don't have this requirement. Just curious, Aleko
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
2
by: Neo | last post by:
Hi, I am new to C++ and want to know what are forward declarations and any site which has a good introductory explanation. thanks in advance, nick
12
by: fox | last post by:
How do I (portably) make a forward reference to a static (I mean file-scope) variable? I've been using "extern" for years, for example: extern int x; int foo(void) { return x++; }
2
by: Carlos Martinez Garcia | last post by:
Hi all: I usually make forward declarations in headers. Something like this: class MyClass; Now, I need a reference to a type defined like this (traditional C Style): typedef struct {
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
0
by: Rune Allnor | last post by:
Hi all. I have these classes, implemented as templates in header files. Right now I have one file per class, where both the declarations and implementations of one class are located in each...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.