Domain: boost.org
Stories and comments across the archive that link to boost.org.
Comments · 395
-
What about other platforms?
> Codehaus is a similar site with a lot of cool stuff.
There's also boost for C++ developers. It is not a large repository but it contains important building blocks.
I wonder if there is any decent code repository for .NET -
Don't Fall For Premature OptimizationsI almost never have problems with performance in Python, and I program in it exclusively. For those things where performance really matters -- e.g., image processing -- there are library written in C that are available from Python (and fairly easy to use) like PIL. There are lots of algorithms in Python itself that are extremely fast, like a great hashtable implementation (Python dictionaries) and sort algorithm.
If it's really a problem, there are a myriad of solutions -- Numeric and numarray for lots of numbers, psyco for JIT optimizations, Pyrex for a Python-like syntax that compiles to C (and can be as fast as C if you use it correctly), and lots of other new options as well -- IronPython is supposed to be faster than CPython (the standard implementation), there's quite a bit of work on type inference, PyPy is working hard at compiling Python to fast C, Boost can inline C++ code... there's a huge number of options.
I've never encountered someone who had to throw a project away because of performance issues in Python. Sometimes they have to change the design, move some small parts of C, make better use of other people's libraries, and always of course driven by profiling -- but that's the kind of refactoring that always happens in development. And for a very large number of applications it simply is never a problem.
-
Re:I don't "get" Mono either.
In fact after searching I realized there are a couple of gotcha's with the auto_ptr (such as copying), but they are much easier to avoid than forgetting to type something in the Java example.
auto_ptr may occasionally be useful, however, in most situations shared_ptr works better. Unfortunately, shared_ptr is not in the Standard, however, it is being standardized, and it has been offered for a while by many compiler vendors. Even if your compiler/standard library doesn't have it, there is always the Boost version, which also offers other smart pointers.
-
Re:Regexes are overused
Consider the boost libraries http://boost.org/.
You get tokenizer, regex, and a parser library (spirit), in sorted by increasing caliber.
It's all about the right tool for the job. -
Re:Slashdot standards?You can't write documentation without asserting something about the reader.
Does "no clue" imply that this is the first time they've ever tried coding something?
In this case, you want to write something gentle. The python tutorial is one notable example of what to do there.
However, if you're talking boost, the 100-level stuff isn't going to win applause.
One thing I haven't seen yet in this thread is the task-oriented, or 'cookbook' approach, that serves at least two distinct purposes:quick-n-dirty steps for the initiated
nice feature overview, to highlight functionality you may not yet be using.
Another thing unmentioned in the thread in indices. For documentation of size, the better the indices, the more useful. -
boost, please ?
Can we get Boost in standard library please ?
-
Use open tools only!Here's the big thing: only use open tools.
What happens three years down the road when Management decides not to renew the Rational Rose license? What happens when IntelliJ stops supporting your version of IDEA and you have to upgrade with money you don't have? Etc.
Use only open tools. Open-source is best, of course, but anything that uses completely documented file formats and has tools for exporting to other formats is acceptable.
Don't let yourself get nailed with vendor lock-in. That's a bad, bad place to be. Better to use slightly inferior tools which are open than to lock yourself to a vendor.
That said, here are the tools I find myself using again and again:- C++
- jEdit is a Java programmer's editor with excellent C++ support. I do development on Linux, Win32 and MacOS X, so it's very nice for me to have one editor I use on every platform. jEdit's not as featureful as, say, Emacs, but it's considerably more friendly to use.
- Boost. If you're writing C++ and you're not using Boost, you're committing a crime against yourself.
- Python. With Boost's Python library, it's easy to make your C++ applications scriptable. Write the heavy lifting parts in C++, then make those parts callable from Python. Do the rest of your development in a far safer, more sane language. You get almost all of the speed of C++, and far fewer headaches.
- SWIG is another tool that's excellent for creating scriptable C++ applications.
- Subversion for your version-control needs. Nothing else will do.
- Doxygen for all your documentation needs. Learn it, love it. Your code's not done until every public part of the API has been doxygenated.
- The GNU Autotools are really, really awful. They're also far better supported than Scons or pick-your-Autotools-replacement. Get ready to feel the pain of m4 macros. Sorry.
:( - The GNU Compiler Collection started getting a good C++ compiler around version 3.0. I've been quite favorably impressed with 3.3, and I'm looking forward to 4.0. I don't recommend it for Windows, but for Solaris and x86 Linux it's beautiful.
- I haven't found a good C++ unit testing framework yet. If you find one, please let me know.
- Java
- Eclipse is an excellent Java IDE. jEdit also fits the bill nicely, if all you want is an editor. I use both frequently, and am quite pleased with both.
- Subversion again for your version-control needs.
- jUnit for unit tests. Your code's incomplete unless you've written unit tests for it.
- Javadoc for documentation. I would recommend Doxygen, but it's quite possible you'll be deploying your applications on machines that don't have it installed.
- Ant for all your build needs.
- C++
-
Don't write C++ without boost!Don't even think about writing C++ code without using boost. In particular, everyone should be using their smart pointers. IIRC, they've been proposed for inclusion in the C++ standard and it's likely to happen.
boost also has a nice unit testing library. I use it for all my C++ code.
-
Don't write C++ without boost!Don't even think about writing C++ code without using boost. In particular, everyone should be using their smart pointers. IIRC, they've been proposed for inclusion in the C++ standard and it's likely to happen.
boost also has a nice unit testing library. I use it for all my C++ code.
-
Don't write C++ without boost!Don't even think about writing C++ code without using boost. In particular, everyone should be using their smart pointers. IIRC, they've been proposed for inclusion in the C++ standard and it's likely to happen.
boost also has a nice unit testing library. I use it for all my C++ code.
-
Sounds like an ambitious undertakingFrom the article: (referring to Adam) "The code providing this functionality accounts for a third of Adobe's code base and nearly half of the bugs found during development."
combined with: "The Eve layout engine has already saved Adobe millions of dollars in localization costs."
Means this contibution (mainly UI work based on Boost) is a very decent contibution.
-
Re:not in c++Except that there are not so called "smart pointers" defined by Standard C++.
An auto_ptr is part of the standard template library (STL) and it is a kind of smart pointer. The STL is a c++ standard. Unfortunately in can't be used in containers. Boost http://boost.org/ has an excellent collection of smart pointers which may become part of a future c++ standard.
-
Re:Write C for C programmers
It's interesting that the "if ( !ptr )" form more directly expresses the intent. One often uses a smart pointer class, like boost's scoped_ptr, which doesn't allow implicit conversion to a pointer, but does overload the ! operator to allow this way of checking its value. With one of these, only the above form works.
-
Exactly!
If you work with C++, boost-serialisiation is the best solution, as it also is part of an upcoming standard!
-
boost.serialization
Boost has boost.serialization which takes care of such things as pointers. Check it out.
// ville -
Object-based approach...
I'm not a CompSci student -- so I don't know the strict definitions of things, but I think this, below, counts as more of an object based approach as opposed to true OOP.
The basic idea is that the thing you're trying to do, ie. have saved game state, ought be a first class thing. So have a global singleton that manages this, and have objects register themselves to that class, then most of the boilerplate can be collected in the global object.
In C++, a better approach would be something like that taken by Boost.Serialization, which provide a template (STL style) framework, so that you can plug in different ways to marshal data as well as different output formats, etc. -
Re:Portable code
Actually, wxWidgets would be a better choice. It is stable, and it is open source and free on all platforms.
Combine this with SDL (Simple DirectMedia Layer) and Boost.org, and you get a great cross-platform development toolset. SDL is "a Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer."
Boost provides cross platforms threading and other nice things. If you keep your GUI seperate from from the main guts of your processing, you can do cross platform programming rather well. -
Re:Portable code
It's not really that hard if that's what you have in mind. Things like Boost can really help, if you can convince whoever your coding for that portability is a good thing.
The problem usually comes when dealing with the GUI or other slightly lower level system functions which sometimes can't be wrapped elegantly. -
Libtorrent
Exeem uses libtorrent as its codebase, with extra coding for the decentralized tracker. Libtorrent is an open source GPL'd C++ implementation of the bittorrent protocol. The only requirements for compiling it are support for STL and the latest Boost. This means it works in Windows, Linux, Mac OSX... even cygwin! It's also a library, so it can be plugged into any application.
I've had many communications with the creator, and he's a very cool guy and quite dedicated to the work. I helped a little with debugging, etc, but my main interest at the time was using it to in my own graphical interface. I never completed the project, but I still feel a good connection to libtorrent. -
Autoconf sucks - use PMK instead
I found PMK to be MUCH easier to work with than the autoconf nightmare. Also, if you are doing C++, check out the Boost libraries, which hide most of the cross-platform complexities for you.
-
Not expressive enough
... and never will be. UML assumes that everything can be reduced to boxes. There are things I can say in code, that I would like to have another notation for. If UML is truly "unified," show me the UML (sequence diagrams, in this case) for the following code (explained here):
(defun make-load-form-with-fixup (obj)
(multiple-value-bind (alloc init) (make-load-form-saving-slots obj)
(setf init (nsubst 'o obj init))
`((lambda (o) ,init o) ,alloc )))Better yet, show me the sequence diagram for this function's caller. Or, since Lisp is supposedly dead, how about this:
sub sort_versions {
return map { $_[0] }
sort { $a[1] <=> $b[1] }
map { [ $_, split /-\./ ] } @_;
}Want an example in a more contemporary language? Then just draw a UML diagram of, say, Spirit , for instance. The control flow here simply cannot be reduced to boxes. UML can't deal with RAII in C++, or finalize-time operations in Java. UML is fundamentally a decent whiteboard tool for some of the less complicated and less expressive languages. That's all it is. (Except for use cases, which have somewhat more broad applicability.)
-
Re:Qt saved C++
Really? More than Boost? A few of their libraries will be in the next C++ standard.
-
valgrind
-
Re:Another statically typed language?One thing that the complexity of C++ enables is the ability to extend the language with some easier-to-use constructs. How about the above example with the help of Boost's assignment library:
#include <boost/assign/std/vector.hpp>
Type-safe and pretty.
using namespace std;
using namespace boost::assign;
int main(void)
{
vector<int> v;
v += 1,2,3,4;
return 0;
} -
Re:Another statically typed language?One thing that the complexity of C++ enables is the ability to extend the language with some easier-to-use constructs. How about the above example with the help of Boost's assignment library:
#include <boost/assign/std/vector.hpp>
Type-safe and pretty.
using namespace std;
using namespace boost::assign;
int main(void)
{
vector<int> v;
v += 1,2,3,4;
return 0;
} -
Re:I *want* to be enthused, but...
If you're going to nitpick about how man CPU instructions it takes to return a std::string, you better not use any high-level language.
Take a look at the job market, good knowledge of C++ is still an invaluable skill.
Moreover take a look at libraries like boost or systems built on C++ like KDE. Well written C++ can be just as elegant as any language (it's always in the programmers hands, they can turn anything in to spaghetti). There's a reason why it's been so popular and many of its concepts are used in other languages (not to say that it was original in its ideas, but in its use of them). -
Re:Writing extensions...
The Boost project has Boost.Python. I haven't used it yet, but the docs make it sound very interesting. It looks quite simple to write base classes in C++ and then subclass them in Python.
-
Re:Writing extensions...
The Boost project has Boost.Python. I haven't used it yet, but the docs make it sound very interesting. It looks quite simple to write base classes in C++ and then subclass them in Python.
-
Re:Dumb Person...
This is one of the more insightful comments in this whole torpid flame war. Those who think that C++ is a broken language, check out Boost, which are a set of extensions to the STL (and sometimes fixes -- these are the people who will change the C++ standard in future). Those who think that C++ is nirvana for the soul, check out the past attempts by the same experts (I sincerely believe that there are no other people in the world who can write C++ to the same standard). I personally like to use whatever language is best suited, and that means suited to me as well as to the project. Often, dotNET (I use Mono, so don't killed me, mods...) might be a technically better solution, but I will go with Python simply because I have more experience with it. Therefore, on this issue I am undecided. Someone else has already pointed out that our current kernel developers are quite C orientated, which means that they won't be as clued up on C++ patterns + idioms than someone who dreams about metatemplate programming. There are a lot of things that can go right with putting C++ in the kernel, but a seriously large amount that can go wrong as well.
-
Re:Exceptions are suddenly viable?
The second is dead wrong- to ignore an exception, just catch all exceptions and do nothing. I know a lot of programmers who do just that to get rid of exceptions they can't fix.
Heh. Yeah, I've heard of that happening quite a lot in Java (not so much in C++, but still to some degree). There's two points I'd make about that:
-
To ignore an error/exceptional-condition indicated by the return code of a function, you literally don't have to do anything. You have to do something active to respond to the "message" indicated by the retval, but you don't have to do anything to ignore it.
With a C++-style exception (and, indeed, most exception systems I know of) you have to do something active to prevent an exception propagating further up the call stack. So you must do something in order to "ignore" an exception outcome - which effectively means that you're not ignoring it
:).It might seem like I'm splitting hairs here, but it is an important distinction.
- Just catching exceptions and blithely going on as though nothing went wrong is not safe - no more than it's safe to ignore an error retval from a "normal" function. Programmers don't (normally
:-)) throw pointless exceptions just for the hell of it. The whole point of a function throwing an exception is to indicate "I couldn't do what I'm supposed to do" and usually to give you some useful information as to why.
[AuMatar also said:]
Thats a bug in constructors, not a valid reason for exceptions.
Heh. I'll let you argue that point with Bjarne.
:-)In any case, if you really want to "return" a value from a constructor, you can do it in the same way you can for any other function with a void return type. You can add an extra reference parameter, eg.
void square(int a, int& retval) { retval = a*a; }
Yes, it's grotesque - but then so are many other cases where it's natural to return a single value from a function, but the user ends up having to check that returned value just to make sure it's not an error code. The common thing with many POSIX functions being that a retval greater than or equal to zero is a valid return, while something less than zero (or specifically -1) indicates an error (the specific details of the error indicated by an external global variable).
The really nice thing (from my coding perspective) is that when the exception system is used properly, it really facilitates cleaner and clearer code. You can have functions for which the signatures are appropriate and make sense - and you don't have to tie yourself in a knot to handle exception/error situations appropriately.
I still think you haven't quite "got" the whole point of exceptions (I'm not trying to say you're an idiot or anything, mind). I hoped the "Blub Paradox" pointer would indicate more effectively what I meant, but I guess not. If you'd done any programming with the Qt signal/slot system (or the similar-ish Boost.Signals library) you might have a better idea of how using an alternative control flow is a useful concept (though I'm probably drifting away from the main point now
:).I have a similar thing with continuations - I just don't get them, I can't understand what they're good for. I haven't yet found (and comprehended
:)) an programming problem solved using continuations for which I couldn't see (what I thought to be) an equally elegant alternative solution.But I'm willing to accept that there is something to them that I just can't see yet - if only because I'm quite happy to say that the kind of people involved in that sort of language design are almost certainly way way smarter than me.
:)I think you're
-
-
Re:SWIG rocks for plugging into C/C++/Libraries.
-
Re:Meanwhile, C++ goes nowhere
I haven't seen it mentioned in this discussion (not so surprising, 'cos it's about java and c# after all), but anyway: take a look at boost. This is the stuff they hope will be in the next standards. Very nice libs (mostly template magic)
cheers,
mitch -
Re:Meanwhile, C++ goes nowhere
I'm curious, why do we still get buffer overflows in C++ code? I mean, the C++ string type and the vector container have been around for the better part of a decade now, and a standard part of the language for, what, six years? Seven years? And you can grab smart pointers from boost.
So, why do we still have buffer overflows? Is it because of the language? I think my previous paragraph shows that this is no longer the cause, and hasn't been for years. On the other hand, C++ does still allow you to make use of C-style strings, unchecked arrays, etc., so perhaps we can blame C++ because it allows you to shoot yourself in the foot, you just have to be very explicit these days. Or perhaps the problem actually lies in the hideously outdated libraries that people are using, libraries such as the ones Microsoft gives you (I'm not talking .Net here, haven't looked at that) which still inexcusably use C-style strings and generally unsafe memory management. Not that Microsoft is solely to blame, of course. -
C++ templates and turing completeness
I haven't seen formal proof but I have seen people use templates to compute the gcd(greatest common denominator) of two numbers at compile time for example. boost has a lot of interesting things that use advanced template kung-fu.
-
Re:python's list processing rulesDoes that include the spiffy stuff that you can do using boost? I haven't done C++ in a while so I haven't had a chance to really play with boost yet, but I'm led to believe that it lets you get the language down to about that level of compactness.
Personally I'm a fan of (mapcar (lambda (x)
...)) -
Re:why not an opensource game like that?
I know I would love to put together something like GTA:VC or MTA. I'm sure many others have as well. My problem is that I'm perhaps not as good a coder as I'd like to think, and I've never explored game programming before. But I have put a lot of thought into it the last year or two, and have come up with these resources:
- OGRE - an object-orientated graphics engine.
- Open Dynamics Engine - as used by the well-known stair and truck dismount games.
- DIE - a car game in the early stages of development. It uses the two previous libraries.
- Boost - C++ libraries. In particular, there is Boost.Python which allows good cooperation between C++ and Python. That could be useful for scripting the interactive behaviour of the various people, vehicles, weapons, and other devices.
As you say, the key would be in creating a flexible engine at the core. I imagine people adding new vehicles, tools, missions, and venues. I'm not sure what the "aim" of the game would be, but I'm sure people would create things to do. Here's my wishlist of improvements and other ideas:
- Climbing ability. I see lots of ladders around GTA:VC, but can't climb them. The ability to hang onto ledges like Tomb Raider would be useful as well.
- More detailed buildings. Most of the buildings in GTA:VC are just boxes. I'd like the ability to walk inside, use the stairs or elevators, find a sniping position on the balcony or window, etc.
- Focus less on violence. GTA:VC has been heavily criticised for its violence and sometimes even I find it a little too much. I'd like to see more focus on stunts and tricks, mischief, puzzle solving and just simple exploration. Perhaps make the police more likely to catch you when you do something "wrong".
- Different character classes. Perhaps not as detailed as a full-on role-playing game, but do have different types of characters with slightly different abilities. You need variety when multiple people are playing online.
- More interactive elements like light switches, garage doors, elevators, etc. Perhaps the player could obtain a garage door remote control and go around opening peoples garages.
- For the ultimate geek thrill, simulate several thousand artificial people! Get rid of the annoying "background" element of the cars and pedestrians in GTA:VC. Everyone has a house, they travel to work every morning and travel home every evening. Police and police cars actually patrol and have to travel to you instead of just appearing. Likewise with the heavier SWAT vans, police helicopter, and army trucks and tanks. Tourists travel in on planes to the airport, stay at hotels, travel around by day seeing the sights, and leave again by plane. Oh boy, lots of computation and memory and bandwidth! Perhaps a little too far-fetched for now.
-
Re:why not an opensource game like that?
I know I would love to put together something like GTA:VC or MTA. I'm sure many others have as well. My problem is that I'm perhaps not as good a coder as I'd like to think, and I've never explored game programming before. But I have put a lot of thought into it the last year or two, and have come up with these resources:
- OGRE - an object-orientated graphics engine.
- Open Dynamics Engine - as used by the well-known stair and truck dismount games.
- DIE - a car game in the early stages of development. It uses the two previous libraries.
- Boost - C++ libraries. In particular, there is Boost.Python which allows good cooperation between C++ and Python. That could be useful for scripting the interactive behaviour of the various people, vehicles, weapons, and other devices.
As you say, the key would be in creating a flexible engine at the core. I imagine people adding new vehicles, tools, missions, and venues. I'm not sure what the "aim" of the game would be, but I'm sure people would create things to do. Here's my wishlist of improvements and other ideas:
- Climbing ability. I see lots of ladders around GTA:VC, but can't climb them. The ability to hang onto ledges like Tomb Raider would be useful as well.
- More detailed buildings. Most of the buildings in GTA:VC are just boxes. I'd like the ability to walk inside, use the stairs or elevators, find a sniping position on the balcony or window, etc.
- Focus less on violence. GTA:VC has been heavily criticised for its violence and sometimes even I find it a little too much. I'd like to see more focus on stunts and tricks, mischief, puzzle solving and just simple exploration. Perhaps make the police more likely to catch you when you do something "wrong".
- Different character classes. Perhaps not as detailed as a full-on role-playing game, but do have different types of characters with slightly different abilities. You need variety when multiple people are playing online.
- More interactive elements like light switches, garage doors, elevators, etc. Perhaps the player could obtain a garage door remote control and go around opening peoples garages.
- For the ultimate geek thrill, simulate several thousand artificial people! Get rid of the annoying "background" element of the cars and pedestrians in GTA:VC. Everyone has a house, they travel to work every morning and travel home every evening. Police and police cars actually patrol and have to travel to you instead of just appearing. Likewise with the heavier SWAT vans, police helicopter, and army trucks and tanks. Tourists travel in on planes to the airport, stay at hotels, travel around by day seeing the sights, and leave again by plane. Oh boy, lots of computation and memory and bandwidth! Perhaps a little too far-fetched for now.
-
Re:APR
BOOST certainly deserves mention
-
Re:What if I program in C++ ?
I did XP in extreme C++ for about a year (by extreme C++, I mean boostified, Alexandrescu'd C++). We used CppUnit for our test framework.
I'm not especially satisfied with the currently available C++ unit testing frameworks. CppUnit and Boost's both have trade-offs. I suspect they'll both get better, though.
The Ant-Contrib project's cc task works pretty well, in my limited experience. I was playing around with it just this weekend. I've yet to set up a tinderbox build process, but I don't see why this wouldn't be easy with either Cruise Control or good ol' cron.
In my mind, the two biggest hurdles with doing XP in C++ are build speed and developer prejudice. You can tackle build speed with a combination of ccache, distcc, good programming principles, and cash. Tackling developer prejudice is harder. A lot of C++ programmers like to write low-level, unsafe, old school C++ code. Modern C++ mostly lets you discard unsafe coding practices without sacrificing efficiency. Whether you can convince an old C++ programmer of this is another matter; it depends on the person. I've had decent success taking Java programmers and teaching them modern C++ via pair programming.
Using Boost helps, indirectly. You write safer code, which gives you a faster development cycle. All in all, I think the basic tools are there. It might be a little harder to get fancy lava lamp integration going with C++, but there's no reason why you can't have a good build process. It's just that a lot of C++ projects haven't evolved (I think this is due, in part, to the fact that the C++ community is late to the internet; a lot of C++ programmers just don't know what's, out there.
cheers,
Jon -
Re:Universally true
> unless you're on the ISO C committee, for example, you have very little influence of the future of the C programming language
This is a little misleading. I sat on the ISO C++ committee's library working group for quite a while (and will resume doing so when circumstances permit), and we were always prepared to consider well thought-out proposals for library extentions (go check out Boost for several examples). All ISO committees have a route for interested parties to make changes to a standard, although it's true that your desired change is much more likely to gain support if you're prepared to join the committee and support the change in person (or can find someone to do so for you) -
Re:I'm going to have to go with "blowhard"
concur.
you might also have a look at boost::python -
Re:Java does not really force handling...
I think the best way is to do what C++ does: it also gives you both declared and undeclared exceptions, but it makes the "can throw everything" case the default for every function.
Java and C++ are very different when it comes to exception specifications. C++ doesn't have the notion of a "checked" exception. Also, C++'s behavior when an exception specification is violated is also very different from Java's. Most experts agree that C++'s implementation of exception specifications is garbage and should rarely be used. See here and here. -
Generic programmingThe ability to do generic programming ala Boost is a great feature. Higher level languages are all about better abstractions, and generic programming is the best abstraction mechanism we've seen in general use since OOP. While OOP lets you encapsulate behavior and abstract over interfaces, generic programming lets you abstract over *form*. The significance is in the coupling. Generic programming allows much looser coupling between the writer of the generic library and the user of the library. A nice example is a generic "find" function:
template <typename I, typename V>
And here, you have captured the essence of a linear search. To understand what's going on, first know that I and V are arbitrary types that are inferred (at compile time) from the values you pass when you actually call the find function. For the generic find function to work, there are only a couple of restrictions on these types:
I find(I begin, I end, V val)
{
for (I it = begin; it != end; ++it)
if (*it == val)
return it;
return end;
}
1) I must be incrementable.
2) I must be dereferenceable.
3) You must get from begin to end in a finite number of steps.
4) The type you get when dereferencing I (I's value type) must be comparable to V.
Because of this, you can use the same find function to search through arrays, lists, vectors, maps, sets, strings, streams, and more, even though none of them inherit from each other or implement a common interface in the OOP sense.
Additionally, there's no complicated syntax for the user of the library:int myarray[10] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55};
The great thing about abstraction is that it avoids duplication. Avoiding duplication lets you test/debug/prove correct once for greater reliability. Once you wrap your head around this simple example, you'll be surprised how deep the rabbit hole goes.
int* p = find(myarray, myarray + 10, 8);
if (p == myarray + 10)
cout << "8 was not found." << endl;
else
cout << "The value of p is " << *p << "." << endl; -
Re:Not entirely free if you're on dial-up
After downloading the VC++ Toolkit 2003 it was sad to see that the C++ standard library implementation appears to lack iostreams..
I've managed to build STLPort and Boost with it though (but not without hacking the source!). Gave me working iostreams at least, but i dont think it was worth it.
I rather use MinGW but it has broken support for wide-char strings
:(. -
Re:Why .NET and not Java?
Multi-Language: Please, they're all the same language designed to look like other languages
Sure, C# and Visual Basic share a lot, but they're the odd ones. See F#, COBOL.NET, Managed Extensions for C++ and the excellent Managed C++ in the works
Java has multi language support to (Jython). This is not a fundamental reason.
Java has poor abstractions, and is based too much on the fallacious "less syntax, more library" principle. Java is the C of managed environments. Sure, you can compile anything into it, but that's just because it's Turing-complete. Must be a lot of fun implementing any useful compiler without delegates and value types
Value Types: Use escape analysis and a better GC. This is a hack so programmers can give hints to a stupid GC.
Value types aren't garbage-collected at all. And they are important for performance and interoperability. Oh, and the
.NET GC does pretty fine, thank you. Whidbey will even let you allocate managed objects on the native heap, and native objects on the managed heap. And you can't do that in C#, this is an uber-geek feature designed for Managed C++, that only further underlines the multi-language and multi-paradigm goal of .NET. Java, in its arrogant engineered "perfection", will never get actually useful stuff like this. Useful how? it gives you a GC heap for free to allocate your own objects on. It lets you use managed objects with the STL, or the excellent Boost. Or use a different GC, like Hans Boehm's, if you don't like .NET's (in fact, the syntax for Managed C++ has been designed with the goal of not conflicting - or even overlapping features - with any of the major C++ frameworks). Without writing a single line of glue code in CGenerics: Where are the C# generics? The version we're using at work doesn't have them.
Whidbey (.NET 2.0). Also previewed in Rotor
Java Generics will arrive first, but be worse off in the beginnnig.
It doesn't matter, because they are a lie. And Java only got them because
.NET didC# language: The only even marginally valid claim. However, the lack of checked exceptions
Microsoft maintains a longeve C++ compiler: they've been there, done that. They never believed in checked exceptions. Nowadays they are mostly agreed with. By all means, look for Herb Sutter's site: like most Microsoft techies with blogs, he gives no-nonsense explanations of all the design choices he's been involved with, and that includes checked exceptions and lack thereof
-
Productivity boost by managed memory is overblown
... Visual Basic is significantly more productive. Often I've written the same code, once in C++ calling the Windows API and once in Visual Basic, and C++ always took three or four times as much work. Why? Memory management.I have experience writing for both platforms, and I prefer C++, despite VB's garbage collection. VB certainly makes it easier to do some things, but that's mainly because it offers an abstraction for all the Win32/COM red tape (dig through the MSDN to find which of the eleven or so Close...(), Delete...(), Free...() functions you need for this thing, and Release() all those COM pointers in every conceivable exit point).
C++ itself provides the means to relieve the programmer of much of this menial work, though. Microsoft doesn't take advantage of C++'s capabilities, but that's probably because C++ hadn't evolved enough when much of the Win32 code base was written.
In my recent work, which has all been C++ on Win32, I almost never have to manually delete anything. The Boost Smart Pointer Library has been tremendously useful, both for internal program logic and for taming the Win32 memory management nightmare. The reference-counting boost::shared_ptr template class and its relatives can be used to automatically free memory allocated with new when the last pointer is destroyed. What's more, you can specify a templatized deleter, so that a shared_ptr can manage COM objects, GDI objects, file handles, memory allocated in any of the dozen or so Windows APIs (GlobalAlloc(), VirtualAlloc(), HeapAlloc(), ThrashDiskAndThenCrashAlloc(), etc.)
It's possible to augment the API in such a way as to boost productivity without breaking backward compatibility. The
.NET framework is a huge misstep, in my opinion, because it needlessly throws away a decade's worth of existing code. We were going to use it in a recent product, but we decided to go with MFC instead, because it couldn't link with our existing C++ code (well, it could, but huge marshalling bugs that have gone unfixed for years made it completely unusable). -
Re:Good move by MS. Unfortunately, WTL sucks.
Well, maybe. The C++ purist in me would still love to see a library implemented without recourse to ugly macros (MFC) or language extensions (QT). I understand why the design decisions were made at the time, but C++ has come on a long way since then. Now that you can treat functions as objects (for example using the boost function library, there's no need for things like message map macros or the MOC to implement to connect gui events to functions. (boost also provides a signals library, that demonstrates this exactly).
The other thing I look for in a library is how lightweight it is. WTL wins hands down here, as it's just a set of header files. No extra libraries to link to or re-distribute. Of course it's not cross platform, but any cross platform library is going to need either a huge interpretation layer for each platform or its own widget set.
Oh well, I guess my quest for the One True Framework will continue.... -
Re:Toss out C.> > Guys, it's time to face the facts. C is a relic from a time when compilers were stupid. Declare all your variables before executing code, declare all your functions before using them, include headers that almost invariably break one another, hurrah.
> > I'm so glad that every time I write C I get to write each function signature several times, that's lovely. In addition, C takes much more time to compoile than Java/C# because all the stupid headers take forever to parse.
> What will you use for your low level device drivers? Or how about that code that needs run fast?
You're complaining about the virtual machine aspect of most high-level languages (not D). And the garbage collector of most high-level languages (including D). You haven't addressed his criticisms of C at all. (And how could you? He's absolutely right.)
If this is your only concern, you could easily come up with a language (D-, maybe?
;) that is like D except that it has delete instead of a garbage collector. And then implement smart pointers as in C++. It would have none of the deficiencies of C/C++ that the grandparent mentioned. -
Re:All the C++ programmers are laughing at you...Yeah, "real" programmers keep on coding in C++...they press on despite:
...a high incidence of memory management related problems, which are often very hard to findThat's true of older C++ code. But now there are very good smart pointers classes. I just don't have these sorts of problems anymore. At most, I get an unexpected NULL, which immediately causes a SIGSEGV - not so different from Java's java.lang.NullPointerException.
...common security issues, often involving buffer overflowsYou can screw this up in C++, so languages like Java are arguably more secure in this fashion. But C++ is not C. It's easier to do things safely than to screw them up.
...compiler incompatibilities, including frequent lack of proper template support, exception handling, namespaces and so onTrue, but getting better.
...obscure and often terribly non-intuitive syntaxTrue.
...overly complex and redundant idioms necessary to work around language shortcomingsTrue.
-
Re:foreach#define EACH( I , C ) typeof((C).begin()) (I) = (C).begin();\
(I) != (C).end(); ++(I)
Nifty trick - it's dynamic, too, and works with non-STL containers (ie. pointers). It requires run-time type information, which slows (generally) everything down. Also, as a macro, it's not safe, and it may make copies (what if one of I or C is a function call? eg. EACH( I, some_foo()). Very bad! )
For just STL containers you could do something like:template<typename iter, typename foo>
Now you can see the obvious problem with this - it's very close to for_each, and yet very far from your for ( EACH(I,C) ) macro. What you probably really want are lambda functions, per the C++ BOOST library, where you can have lovely things (per their examples) likeso:
void each(iter i, foo&f) { /* &f reference may not be 'good', but meh.
There are some const optimizations that you can make w/
partial specialization, but again, meh. You probably don't
want this. :)
*/
for (i = f.begin(); i < f.end(); ++i)
{ f(i); } /* functor */
}for_each(vp.begin(), vp.end(), cout << *_1 << '\n');
This is not a macro, so you don't lose the type safety, and it doesn't recreate (C) and (I) everytime they are called, and thinking ahead, doesn't store them in a temporary global variable so it's thread safe.