Thread overview | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 26, 2007 C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
An interesting and sometimes amusing read: http://yosefk.com/c++fqa/ |
October 26, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | "Walter Bright" <newshound1@digitalmars.com> wrote in message news:fft2ak$2m38$1@digitalmars.com... > An interesting and sometimes amusing read: > > http://yosefk.com/c++fqa/ speaking of faq - not fqa :) someone should take a few minutes and write a few sentences to http://www.digitalmars.com/rtl/gc.html for programmers who never used GC and what should it mean to them, possibly with an example. And by example I mean "So, should I just declare pointers with objects on the heap with new and without delete anywhere or what?" .. and then a simple explanation with example. If it already exists somewhere on the site - there should be a FAQ: How to find stuff on this site |
October 27, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright Wrote:
> An interesting and sometimes amusing read:
>
> http://yosefk.com/c++fqa/
In amongst the religous fervour (of the defective C++ bit) there are some genuine points. The amusement comes from the obviously java biased/blinded viewpoint of the author. It seems to me the main retorts to this fqa is the C++ is spiderman retort "With great power comes great responsibility" another less polite one that comes to mind is the Harry Hill retort "If its too hard I can't understand it". Templates add a whole new dimension to typing that flatlanders find hard to grasp at first.
Leaving the poor education aside D seems to address all the genuine concerns except reflection and inlining. I know reflection will be added eventually but what about inlining. Isn't inlining available via mixins?
[OT]
Someone at work pointed out this java chestnut recently. If you've used java much you will know it but it may come as a shock to a mainly C++ coder.
class foo {
bar x;
void foo () {
x = new bar();
}
}
foo is NOT a constructor its actually a method named foo. The java compiler or interpreter generates a default constructor that sets all members to null so any use of x in any method of foo will result in a null pointer exception. This apparently compiles with no warnings.
[/OT]
|
October 27, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruce Adams | Bruce Adams wrote:
>Isn't inlining available via mixins?
Isn't inlining available via the compiler switch -inline (for DMD)?
Thanks,
Nathan Reed
|
October 27, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nathan Reed | Nathan Reed Wrote:
> Bruce Adams wrote:
> >Isn't inlining available via mixins?
>
> Isn't inlining available via the compiler switch -inline (for DMD)?
>
> Thanks,
> Nathan Reed
Good point. I'm a gcc/gdc person by preference. But it is an optimisation and as such its not a bad idea to leave it as a compiler option. For a start you can inline differently from module to module that way. Then again a mixin would achieve the same localisation of optimisation in a compilation independent way.
Regards,
Bruce.
|
October 27, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruce Adams | Bruce Adams wrote: > > [OT] > Someone at work pointed out this java chestnut recently. If you've used java much you will know it but it may come as a shock to a mainly C++ coder. > > class foo { > bar x; > void foo () { > x = new bar(); > } > } > > foo is NOT a constructor its actually a method named foo. The java compiler or interpreter generates a default constructor that sets all members to null so any use of x in any method of foo will result in a null pointer exception. This apparently compiles with no warnings. > [/OT] What's so surprising about that, even for a Java newcomer? -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D |
October 27, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruce Adams | Bruce Adams escribió:
> Walter Bright Wrote:
>
>> An interesting and sometimes amusing read:
>>
>> http://yosefk.com/c++fqa/
>
> In amongst the religous fervour (of the defective C++ bit) there are some genuine points. The amusement comes from the obviously java biased/blinded viewpoint of the author. It seems to me the main retorts to this fqa is the C++ is spiderman retort "With great power comes great responsibility" another less polite one that comes to mind is the Harry Hill retort "If its too hard I can't understand it". Templates add a whole new dimension to typing that flatlanders find hard to grasp at first.
> Leaving the poor education aside D seems to address all the genuine concerns except reflection and inlining. I know reflection will be added eventually but what about inlining. Isn't inlining available via mixins?
>
> [OT]
> Someone at work pointed out this java chestnut recently. If you've used java much you will know it but it may come as a shock to a mainly C++ coder.
>
> class foo {
> bar x;
> void foo () {
> x = new bar();
> }
> }
>
> foo is NOT a constructor its actually a method named foo. The java compiler or interpreter generates a default constructor that sets all members to null so any use of x in any method of foo will result in a null pointer exception. This apparently compiles with no warnings.
> [/OT]
In D:
class Foo {
private {
int x, y;
}
static {
float SomeGlobalVariable;
this() {
// Do some global initializations
}
}
}
Nope, no compiler warning here either.
At least Eclipse gives you a warning saying "That method's name is the same as the class' name". :-)
|
October 27, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | Bruno Medeiros Wrote:
> Bruce Adams wrote:
> >
> > [OT]
> > Someone at work pointed out this java chestnut recently. If you've used java much you will know it but it may come as a shock to a mainly C++ coder.
> >
> > class foo {
> > bar x;
> > void foo () {
> > x = new bar();
> > }
> > }
> >
> > foo is NOT a constructor its actually a method named foo. The java compiler or interpreter generates a default constructor that sets all members to null so any use of x in any method of foo will result in a null pointer exception. This apparently compiles with no warnings.
> > [/OT]
>
> What's so surprising about that, even for a Java newcomer?
>
> --
> Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Its the fact that a simple typo can cause such mayhem. Remove the void from foo() and it becomes a constructor and everthing works just fine.
|
October 27, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruce Adams | Bruce Adams wrote: > Bruno Medeiros Wrote: > >> Bruce Adams wrote: >>> [OT] >>> Someone at work pointed out this java chestnut recently. If you've used java much you will know it but it may come as a shock to a mainly C++ coder. >>> >>> class foo { >>> bar x; >>> void foo () { >>> x = new bar(); >>> } >>> } >>> >>> foo is NOT a constructor its actually a method named foo. The java compiler or interpreter generates a default constructor that sets all members to null so any use of x in any method of foo will result in a null pointer exception. This apparently compiles with no warnings. >>> [/OT] >> What's so surprising about that, even for a Java newcomer? >> >> -- >> Bruno Medeiros - MSc in CS/E student >> http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D > > Its the fact that a simple typo can cause such mayhem. Remove the void from foo() and it becomes a constructor and everthing works just fine. > > No one in the Java world writes classes with lowercase first letter anyways. :P -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D |
October 27, 2007 Re: C++ frequently questioned answers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ary Borenszweig | Ary Borenszweig wrote:
> In D:
>
> class Foo {
>
> private {
> int x, y;
> }
>
> static {
> float SomeGlobalVariable;
>
> this() {
> // Do some global initializations
> }
> }
> }
>
> Nope, no compiler warning here either.
>
> At least Eclipse gives you a warning saying "That method's name is the same as the class' name". :-)
Static constructors are allowed, they don't replace the regular constructor. Or wasn't that what you meant?
|
Copyright © 1999-2021 by the D Language Foundation