Možda najinteresantniji citat o problemima C++a sam našao na jednom Java sajtu. Mada Java programeri često potežu potpuno pogrešne argumente kad kritikuju C++, ovaj tip zna šta priča:
http://www.theserverside.com/n...read.tss?thread_id=21924#98770
Citat:
I can and do use alot of discipline when developing under C++, and use a subset that I can keep under control. Many other developers I know also do the same thing.
The problem is, no two developers ever agree on the subset. One guy won't use exceptions. Another one avoids multiple inheritence. A third won't use templates. One hates operator overloading. And a fifth guy uses C++ only as "better C" and has a handy-dandy header library of 4,236 macros for fun and amusement. Half of them don't understand references and use pointers exclusively, the other half avoid pointers like the plague. Some joker uses operator() in every class for some funky reason that nobody but him understands.
On the "positive" side, someone will aggressively use templates. Another has a love affair with operator overloading. A third thinks virtual inheritance is the cat's ass. One uses exceptions whenever possible.
Now on the "my head is imploding" level, add in a C++ super-user, or a newbie who's determined to use the entire language. Add in a quarter of the code that uses old RogueWave container stuff. Another quarter that uses STL. Another quarter that uses a botched and butchered psuedo-STL that barely crawls along the floor that they got off the net. Another quarter have their own container classes they wrote a five years ago and refuse to part with.Some guys use ISO C++ I/O mechanisms. Some guys use old C mechanisms. A subset of them use C and Unix mechanisms. The guy who has an office but always keeps the lights off uses a Swifty++ I/O package he downloaded off the net 5 years ago. One woman wants to use a Posix threading library, the grizzly-adams-looking guy who has 12 seconds more seniority insists on using the native OS threading libraries directly. The crotechtety old man with 15 monitors surrounding his cube - all VT102 terminals - still uses (void *) for all his callback data. The stunningly beautiful red head on the 5th floor runs ISO compatability suites on everyone's code and sends 37 page e-mails to everyone lambasting them for non-standard code. The equally stunning brunette in the next cube over sends 37 page plus 1 line e-mails detailing why she needs to use every non-standard feature of the compiler and libraries to meet her deadlines.
Now - try to combine these people's code into a rational system. You can try development standards, mandates, code reviews, and many other practices, but the problem is that C++ is just too damn big, and ironically specifies almost nothing useful library wise, and no two people - even reasonable expert level people - can agree on what's a good practice and what's not.
The problem isn't finding a subset you can live with. The problem is living with everyone else's subset in addition to yours and trying to make it all work somehow.
Ovo je ozbiljan problem. u jednom velikom projektu koji povremeno održavam, srećem se sa bar 5 različitih klasa za string. Tu su naravno MFC CString, standardan std::string i std::wstring, pa Xerces-ov DOMString, pa neki in-house stringovi, a i da ne pominjem stari, dobri char*. U poslednjih godinu dana, usvojili smo neke fine code standarde kojima se sprečavaju ovakve stvari u budućim projektima, međutim vrlo malo projekata počinjemo "od nule", već uglavnom nadograđujemo stare. Čak i u slučajevima kad krećemo iz početka, često želimo da koristimo neke gotove biblioteke i problem se opet javlja.
Uostalom, i sam Bjarne kaže:
http://www.research.att.com/~bs/bs_faq.html#really-say-that
Citat:
also said "Within C++, there is a much smaller and cleaner language struggling to get out." For example, that quote can be found on page 207 of The Design and Evolution of C++. And no, that smaller and cleaner language is not Java or C#.
E sad, kako su kreatori Jave i C#a "rešili" te probleme:
1) Iz jezika su izbacili sve što je po njihovom mišljenju "komplikovano", uključujući neke nesumnjivo korisne elemente (šabloni, const metodi, podrazumevani parametri višestruko nasleđivanje) i tako de facto napravili korak nazad. Sad vraćaju neke od tih elementata (generics), ali šteta je već napravljena - napisana je gomila koda koja se oslanja na prevaziđene metode generičkog programiranja i to treba održavati.
2) Usvojili su prevaziđen i rigidan objektni model po kome se sve trpa u jednu "kosmičku" hijerarhiju. Ovo onemogućava primenu modernih OO metodologija kao što su mixins-i i vodi nepotrebnom dupliranju koda. Ostavio sam neke interesantne linkove sa tim u vezi na temi o višestrukom nasleđivanju u Javi.
3) Vezali su jezike za obavezan, nedeterministički Gargbage Collector. Da se razumemo, ja nisam jedan od onih hardcore C supermena koji smatraju da pravi muškarci sami brinu o memoriji i drugim resursima. Naprotiv, automatska kontrola resursa je vrlo poželjna stvar - međutim rešenje koje nam nude i Java i .NET je jednostavno pogrešno i pruža lažnu sigurnost programeru dok se u suštini otvaraju vrata za razna curenja resursa. C# pruža dodatni mehanizam da zakrpi ovu rupu (IDispose interfejs), ali je to rešenje komplikovanije i rogobatnije nego čak i delete u C++u, a da i ne pominjemo čist i jednostavan RAII idiom (Googlajte malo ako niste čuli za RAII) koji stoji na raspolaganu C++ programerima (avaj, malo njih ga poznaje, a kamoli koristi). Posebna priča je što programi pisani u ovim jezicima u praksi "jedu" tolike količine memorije da je to često potpuno neprihvatljivo - posebno za desktop aplikacije.
4) Ogromne loše dizajnirane biblioteke koje sadrže sve i svašta i koje vremenom postaju pune "deprecated" klasa i metoda. Dobar primer za ovo je java.util.Date klasa:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html
Od 6 konstruktora, 4 su "deprecated", a od 28 (ako sam dobro izbrojao) "običnih" metoda, 17 su "deprecated" !!!!! .NET klase za sad nemaju takvih problema jer su nove, međutim čekajte samo Visual Studio 2005 - kladim se da će taj fenomen da se pojavi.
Ne kažem, postoje i stvari koje mi se dopadaju, posebno kod C#-a, a jedna od njih je "kontrolisana virtualnost" sa new i override.
Najzad, da odgovorim na pitanje - ja ne bih "krpio" C++ - idealno bih voleo neki jezik koji sintaksom uopšte ne podseća na njega a nudi njegovu fleksibilnost i moć.