The Artima Developer Community
Sponsored Link

Weblogs Forum
Why? Language Archaeology ... and Metaprogramming

89 replies on 6 pages. Most recent reply: Sep 14, 2009 4:31 PM by Andy Dent

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 89 replies on 6 pages [ « | 1 2 3 4 5 6 | » ]
Neeraj Sangal

Posts: 4
Nickname: nsangal
Registered: May, 2005

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 17, 2009 10:21 PM
Reply to this message Reply
Advertisement
Bruce, thanks for your continuing explanation on the evolution of C++. You have often observed that the complexity of C++ was not gratuitous but a necessary consequence of compatibility with C.

However, I feel that C++ did not just stay "compatible" with C, it also attempted to remain true to the “spirit” of C. For instance C does not have a “class” construct. I wonder if at least some of the problems are a result of trying to treat a "class" just like a "struct" or any other data type. For instance, could it have been have been possible to require that class objects are always allocated on heap and that they are always passed by reference? Wouldn't this have avoided the complexity associated with implicit constructor calls? Perhaps, it could also have required that a class never spans multiple files or even prohibited a file from containing multiple classes. Even the C++ name space declaration for which there is no counterpart in C, could have been less flexible but simpler.

John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 1:09 AM
Reply to this message Reply
> For instance, could it have been have
> been possible to require that class objects are always
> allocated on heap

You're forgetting that C++ encompasses many different platforms and uses.
In the embedded and realtime areas, forcing heap allocation for ALL classes would be a performance bottleneck and inhibit deterministic operation.

John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 1:17 AM
Reply to this message Reply
> They could easily have said Cat x = Cat() or Cat x = Cat("mittens").

Why not just Cat x("mittens")
It supplies all the same information.

Tasos Zervos

Posts: 17
Nickname: tzervos
Registered: May, 2003

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 4:35 AM
Reply to this message Reply
> > They could easily have said Cat x = Cat() or Cat x =
> Cat("mittens").
>
> Why not just Cat x("mittens")
> It supplies all the same information.

Is this some sort of campaign to reduce RSI?
I find most similar discussions on boilerplate and ceremony too theoretical. I had a similar feeling about micro-benchmarking discussions...
It is somehow this "elegance" in the micro scale that I find unacceptable in Maths notation. A race to reduce black-board space!
Eventually there is so much brain power used in constant processing of this ultimate "efficiency" that real creativity is held back...

What I really like is writing in the style of the Head-First book series!
What you read is what is there; no extra interpretation processing; no reading between the lines; no implied consequences.
It is the clear notation, clear location of code, no-magic side-effects, etc. that allow (me at least) to get elegance in the macro scale.

Put another way, I can write code without my "computer" glasses on but only for some hours while some brain power is always used for visual processing instead of creative processing. With them on, I can code for more hours and once in the zone all my brain power can be on the creative task!

Having said that, "clearness" is only a prerequisite.
I've seen far too much Java code and apps that, despite the language philosophy, are designed for the micro scale and suffer anyway.
Probably, this is more a lack-of-design issue... :-(

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 5:09 AM
Reply to this message Reply
> > C++ does not have flaws because of compatibility with
> C.
> > C++ has flaws because it was not thought out well.
>
> This is precisely what I'm arguing against. If you had
> been there as I was, you would have seen very smart people
> excruciatingly going over each decision, discovering all
> the problems before adding features. It was thought out
> *extremely* well, and the reason the language is difficult
> is precisely because of C compatibility.
>
> Oh. Wait. You're trolling, aren't you. You got me. Good
> for you.

No, I am not trolling at all. Having worked with C++ for the last 11 years, and having used every feature of the language, I know that there are alternatives that could have been chosen that could have made the language much better.

Some examples:

1) the distinction between classes and non-classes types. All types could have been classes, even primitives.

2) uninitialized variables. Variables should always have been initialized to their default value. If there was a performance issue, then the programmer should have a keyword in his disposal telling the compiler to allocate memory for the variable but not initialize it.

3) default values for parameters only at the end of the parameter list. A function could have default values in any of its parameters, not only in the parameters of the left side of the parameter list.

4) lack of pass-by-name parameters. Why C++ doesn't have it? there is nothing that has to do with C combatibility.

5) the choice of angle brackets for template parameters. This was a mistake that made the grammar a lot more ambiguous than what it was.

6) the choice of syntax '= 0' for abstract methods, because of fear of introducing another keyword. Nothing to do with compatibility with C.

7) lack of anonymous functions. They could be very simple, i.e. not be closures, not capture the environment. They could be localized parametrized pieces of code that refer to hardcoded addresses (so there is no need for the extra data pointer). Again, nothing to do with C compatibility.

8) lack of tail call optimization. Again, nothing to do with C compatibility.

9) lack of compile-time introspection of classes properties (class names, class members, class member types, class member names, etc). Again, nothing to do with C, but it would greatly simplify a lot of code.

10) initializer lists. They could have been part of the constructor code.

11) lack of static initialization of class members as a separate function. The same code must be repeated over and over in each constructor.

12) uniform construction syntax. Again, nothing to do with C. C(a) and C = a should have been equal. C++0x solves this with C{}.

There is a lot more of this stuff. The list of things that could have been better contain a lot of items.

So...obviously I am not trolling, as you say. C++ could have been much better right from the start. It is just that it was not thought out very well.

Hoang Vu Nguyen

Posts: 3
Nickname: vu64
Registered: Apr, 2008

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 5:37 AM
Reply to this message Reply
Dear Margaritis, I don't want to cause any flamewar but I must have seen you crying about C++ for more than ten thousand times on various forums. Most of the time, you just delve on the lack of garbage collection in C++. I think you should spend more time investigating what modern day C++ is.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 6:14 AM
Reply to this message Reply
> 3) default values for parameters only at the end of the
> parameter list. A function could have default values in
> any of its parameters, not only in the parameters of the
> left side of the parameter list.

This could probably be made to work but wouldn't it create ambiguity with overloaded methods?

Cedric Beust

Posts: 140
Nickname: cbeust
Registered: Feb, 2004

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 7:24 AM
Reply to this message Reply
Hi Achilleas,

I'll just pick on one of your points:

4) lack of pass-by-name parameters. Why C++ doesn't have it? there is nothing that has to do with C combatibility.

Because it can be very easily simulated with the language as it is:

Window w = new Window().color(RED).width(100).height(150).

A lot (although probably not all) of your questions have answers of the same caliber: whenever a feature is missing, it's very likely to be for a very specific reason that was probably not very well documented (I highly recommend "The Design and Evolution of C++", if you want to get an insight on how C++ became what it is today).

I still think that C++ has become a monstrosity and I'm thoroughly disappointed by how Stroustrup has been dissing Java these past years, but let's try to be fair.

John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 7:54 AM
Reply to this message Reply
> > Why not just Cat x("mittens")
> > It supplies all the same information.
>
> Is this some sort of campaign to reduce RSI?

No, it's just C++ does it this way and I couldn't think of a good reason why it would be impossible for Java.

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 8:33 AM
Reply to this message Reply
> Dear Margaritis, I don't want to cause any flamewar but I
> must have seen you crying about C++ for more than ten
> thousand times on various forums. Most of the time, you
> just delve on the lack of garbage collection in C++. I
> think you should spend more time investigating what modern
> day C++ is.

I am working on a 120,000 lines of code C++ project as we speak.

But why is it so bad to have GC? it compliments manual memory management nicely.

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 8:36 AM
Reply to this message Reply
> Hi Achilleas,
>
> I'll just pick on one of your points:
>
> 4) lack of pass-by-name parameters. Why C++ doesn't have
> it? there is nothing that has to do with C combatibility.
>
> Because it can be very easily simulated with the language
> as it is:
>
> Window w = new
> Window().color(RED).width(100).height(150).

That's not pass-by-name arguments. That's function chaining.

>
> A lot (although probably not all) of your questions have
> answers of the same caliber: whenever a feature is
> missing, it's very likely to be for a very specific reason
> that was probably not very well documented (I highly
> recommend "The Design and Evolution of C++", if you want
> to get an insight on how C++ became what it is today).

I've read that and it did not answer most of my questions. It gives an insight on why C++ is the way it is, but it does not explain why C++ is not the way it should have been.

John Wellbelove

Posts: 72
Nickname: garibaldi
Registered: Mar, 2008

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 8:49 AM
Reply to this message Reply
> That's not pass-by-name arguments. That's function
> chaining.

He did say simulated

marcelo morsello

Posts: 2
Nickname: morsello
Registered: Nov, 2007

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 9:29 AM
Reply to this message Reply
Bruce, where is Groovy?

Tasos Zervos

Posts: 17
Nickname: tzervos
Registered: May, 2003

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 9:34 AM
Reply to this message Reply
> > > Why not just Cat x("mittens")
> > > It supplies all the same information.
> >
> > Is this some sort of campaign to reduce RSI?
>
> No, it's just C++ does it this way and I couldn't think of
> a good reason why it would be impossible for Java.

John, this wasn't meant to pick at your post. I was already feeling this when reading Bruce's article. I can see that by clicking on the last "reply" link/button this is stored as a direct reply to you. I should have gone back to the original and added the reply there... Or added an explicit @Bruce... :-)

Tasos Zervos

Posts: 17
Nickname: tzervos
Registered: May, 2003

Re: Why? Language Archaeology ... and Metaprogramming Posted: Jun 18, 2009 10:01 AM
Reply to this message Reply
> Bruce, where is Groovy?

Exactly!

This is the beauty of the VM and the bytecode.
When the pay-off of a different syntax is not just theoretical (like less typing...) then I'm for it. Groovy can deliver a lot of value even on top of Java code-bases.

Flat View: This topic has 89 replies on 6 pages [ « | 1  2  3  4  5  6 | » ]
Topic: First Steps in Flex: 6 Screencasts Available Previous Topic   Next Topic Topic: A Generic Ostream Iterator

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use