Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror

Comment Re:Why not Go or Java? (Score 1) 546

Yes: GCC has, in fact, been bootstrapped with a C++ compiler, and works the same that way as when compiled with a C compiler. It took some work, but that work has been done.

It arguably leads to more maintainable code, because you get C++'s stronger type checking.

Comment Refutation (Score 1) 546

There are many problems with your example.

  • You can't do non-trivial initialization in the constructor because initializer syntax is not turing complete. Most C++ style guides (such as Google's) suggest using a separate init() function, so it isn't really less lines of code.
  • A constructor can't fail without throwing an exception. Assuming you don't allow exceptions, your class now needs an internal dead state. This is the case even if you use a separate init(), because the destructor needs to know whether init() was successful (unless of course you use a separate destroy(), making this pointless.)
  • A destructor can't fail at all. There is no way to indicate failure; you can't throw an exception because the destructor might be called during stack unwinding from another exception. What if the destructor fails to flush a buffer? The C version can simply return a boolean to indicate this.
  • There is no way to indicate that MyClass should not be inherited, so to allow deletion through a base class pointer (a requirement to satisfy the Liskov substitution principle), your destructor should be virtual. This adds overhead to the class itself, and adds a lot of overhead at the call site if the runtime type cannot be statically inferred.
  • You now need implement (or at least declare private) copy constructors and operator=. Developers expect C++ objects to be copyable, and standard containers require it.

Don't you see what is going on here? Even the most trivial feature of C++, constructors, are horribly ridden with complications. C++ is a language of never-ending surprises, gotchas, land mines. It's a trap.

Let's knock those down one at a time.

  • From the constructor's initialization list you can call arbitrary functions. Whether you should or not is another matter, but it's certainly possible.
  • You can make your constructor take a bool& succeeded parameter if you really can't allow exceptions. (Or even an Error reference.) No worse than C, often better.
  • Destructors can and do fail, but if you want to detect failure instead of ignoring it you should call a function explicitly. No worse than C, often better.
  • You can indicate in a number of ways that MyClass cannot be inherited from; documentation should suffice, but there is also a silly trick you can use if you think that technical solutions to social problems are a good idea. Even without that, you don't need to allow deletion through the base class; just make its destructor protected.
  • If you use resource classes to hold resources (which, it turns out, makes your code cleaner and simpler) then you don't need to do anything about implementing copy operations; the compiler just does the right thing. For your resource classes, you do need to implement them, but there are relatively few such classes, and they're simple.

Comment Bitwise copy is C semantics, not C++ (Score 1) 546

C makes bitwise copies. C++ makes memberwise copies (and in simple cases, can optimize that to a bit copy). In C++ you'd hold a smart pointer, and copying that would do the right thing (whatever the smart pointer defines it to do: ref counting, causing a compilation error, making a copy of the target).

Copy operations in C++ would probably not be implicit, if it weren't for the fact that they're implicit in C.

Comment Name mangling is deliberately different (Score 1) 546

Different name mangling between different compilers is deliberate, and a good thing: it stops you linking together code that uses incompatible ABIs, and then getting strange crashes.

Now, if you want to complain that it took too long to standardize ABIs for C++, and that it's too hard, and that they're not stable enough, then you might well be able to make a pretty strong case, but that's a different thing. If your ABIs don't match, you shouldn't make your name mangling match.

(Incidentally, if you code in a sane way then the implicit copy operations _almost_ always do the right thing. It would still be better if we had to explicitly enable them, but that would have broken C compatibility, or made struct vs class into two different worlds.)

Comment const was in C89, aka ANSI C (Score 1) 546

The ANSI C committee adopted const from C++ in time for the first ANSI C standard, 21 years ago (sadly not calling it "readonly").

(You make a valid point about not having to use every C++ feature to get benefits from using some, and I believe that the plan is to be conservative in introducing features that are helpful while avoiding more controversial or complex features.)

Image

US Grants Home Schooling German Family Political Asylum 1324

A US judge has granted political asylum to a family who said they fled Germany to avoid persecution for home schooling their children. Uwe Romeike and his wife, Hannelore, moved to Tennessee after German authorities fined them for keeping their children out of school and sent police to escort them to classes. Mike Connelly, attorney for the Home School Legal Defence Association, argued the case. He says, "Home schoolers in Germany are a particular social group, which is one of the protected grounds under the asylum law. This judge looked at the evidence, he heard their testimony, and he felt that the way Germany is treating home schoolers is wrong. The rights being violated here are basic human rights."

Apple Orders 10 Million Tablets? 221

Arvisp writes "According to a blog post by former Google China president Kai-Fu Lee, Apple plans to produce nearly 10 million tablets in the still-unannounced product's first year. If Lee's blog post is to be believed, Apple plans to sell nearly twice as many tablets as it did iPhones in the product's first year."

Comment Firefox bug 487638, fixed for Firefox 3.6 (Score 1) 387

(Reposting, logged in this time.)

If you're using Firefox then this bug is/will be fixed in Firefox 3.6, so that it will report the correct website when things are slow instead of saying "Waiting for *.google-analytics.com. See https://bugzilla.mozilla.org/show_bug.cgi?id=487638 for the details; "status bar blames wrong resource when downloading slow responding resource" is the title of that bug.

If you're using other browser(s), let me know which.

Full disclosure: Google is my employer (and I care about making sure Google Analytics isn't slow).

United States

Submission + - How can we convert the US to the metric system?

thesolo writes: "Despite past efforts of the 1970s and 1980s, the United States remains one of only three countries (others are Liberia and Myanmar) that does not use the metric system. Staying with imperial measurements has only served to handicap American industry and economy. Attempts to get Americans using the Celsius scale or putting up speed limits in kilometers per hour have been squashed dead. Not only that, but some Americans actually see metrication efforts as an assault on "our way" of measuring.

I personally deal with European scientists on a daily basis, and find our lack of common measurement to be extremely frustrating. Are we so entrenched with imperial units that we cannot get our fellow citizens to simply learn something new? What are those of us who wish to finally see America catch up to the rest of the world supposed to do? Are there any organizations that we may back, or any pro-metric legislators who we can support?"

Slashdot Top Deals

As long as we're going to reinvent the wheel again, we might as well try making it round this time. - Mike Dennison

Working...