C++ And Other Problems

C, C++, Visual C++, C++.Net Topics
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: C++ And Other Problems

Post by Saman » Thu Aug 25, 2011 3:29 pm

This is an answer to Sandun since I see some misinterpretation in his comments.
For server side applications we use java, and it's very advantageous to use java for that kind of applications.
and C/C++ when we writing standalone programs,which me need to meet the speed.
Java has never been popular for server side developments. PHP is the most popular and proven efficient server side language. Almost all popular web based applications including Joomla, Drupal, etc... are written in php.

C/C++ in the other hand used for system programming (Ex: Windows, Linux, MacOS, Symbian, Android, etc.. list never ends until the final OS.. Sun Java Virtual Machine is another good example which is written in C) but not limited to that. Apache web server, Oracle/SQL Server RDBMS server, PHP interpreter are some good examples of C/C++ use. In simple terms C/C++ in combination with ASM is everything you have really inside ;)

I'm not going to promote C/C++ here :) But the truth is C/C++ is more machine friendly where as Java is kind of a virtualisation of the system. If I elaborate the statement further, JVM has a Stack based architecture (PUSH/POP). If you run Java on a CISC (such as Intel), the JVM has to translate Stack to CISC. If you run on a RISC, then again the JVM translates to RISC. This is where Java is very slow and generally considered a failure for high precision applications.

If you take Android for example, all the OS routines except interface written in C/C++. Java is used to make the interface. This is where Android has a limitation to run only on units with ARM microprocessors (Some ARM processors has a JVM execution mode). In the other hand I don't see any advantage in using Java there in comparison to iPhone/iOS (http://developer.apple.com/technologies/mac/cocoa.html) which is completely written in C/C++. Still iPhone is considered the best user friendly phone in the world.

However Java is used for database oriented applications such as Accounting Systems, Logistics Systems, etc... where there isn't any real need to time precision calculations, etc... I'm not discouraging Java learners. But this is the reality.

However if you learn on language better, you can easily switch to any other language. Syntax & Semantics are almost same.
I just did SCJP on java and I don't have much more experience on java at all. But I found debugging java
is quite easy when compared to C++.
This is COMPLETELY wrong. I use C++ in many platforms for many years now. I never found at least ONE PROBLEM in debugging my code. If C++ has such debugging problems, do you think people would use it for serious work such as OS development, embedded development, etc..? Do you think people like Bill Gates, Steve Jobs, Linus Torvalds, etc.. are mad to use C++? They would never chose a language which they can't debug. Debugging in C++ is very powerful. It seems like you haven't used C++ for any useful code. So make sure don't give false comments on subjects that you don't know exactly as true. Otherwise readers might think your comment is true.
Swing /Awt documentation is more organized and completely object oriented when compared with win32 API or xlib.
I wondering what you are talking about here. What's the relationship between C/C++ and Win32 API. Win32 API is an interface given by Microsoft for their users to do things quickly. Nothing more than that. C/C++ has no relationship other than have the ability to call them when you are on Windows. Java also has the ability call those native DLL functions. So another false comment again.
may be because I learn java before C++ made me to think into the object oriented.
No...It is because you don't have expereince in developing serious applications. If you get a chance to join a company which develops software for foreign markets, you will understand what I have just told you. I do not think local companies do more than database applications, web development and editing open source codes. I say this just because I know ;)

In conclusion, don't get your brain washed with technical jargon. Just learn the concepts in parallel to mathematics. I said there is nothing without C/C++ and ASM on the computer. Similarly there is no science without mathematics. Mathematics lived for centuries and C/C++ is living for decades now.

In my years of expereince, I can clearly tell you, if you don't know C/C++ and ASM (x86 ASM) you are just like a parrot who repeats things that you were taught. You will not be able to think independently and do some serious work other than database applications, etc.... (I'm not going to tell about php for web developers here since everybody knows about it).

I'm open for logical arguments. When you say something, just give facts. Otherwise it will become a personal opinion where nobody is going to believe you or your words.
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: C++ And Other Problems

Post by SemiconductorCat » Thu Aug 25, 2011 9:31 pm

I'm sorry I'm not a experienced developer. I was took my first job and first assignment as a C++ developer but
I failed at my job.Now again I'm a university student.


However I still find Debugging C++ is hard when compared with the Java. These are from my little experience.
if you know new techniques to get rid of these let me also know.
* Generating the call trace directly.
i mean without using direct breakpoints how is the simplest way to generate call trace while running?Without
writing a GDB script or calling a gdb internal macro?
* Condition of a stack smash.
In a university project , guys told me there is a set of code that crashed and we can't debug! What ?
When we take the stack trace it shows addresses of functions that are not valid. Even there is no symbol
assigned to that address. How this happen? Finally a careful code review I realized that it's happening due
to a code block that smash the stack and it will overwrite the return address of the stack and debugger is going
nuts.
* Code runs inside debugger but crashed when we compile without debugging symbols.
This is the nasist thing that I have seen. it's a routine that calling 'kmalloc' directly by it's index. A deadlock
condition causes this nasty trouble. But it's a mistake in our code base , not a mistake in the OS kernel or
compiler yet.
* Compiler / Debugger Bug.
everything have bugs. But I still didn't met a single instance of this kind of bug.

But in java you rarely encounter these kind of bugs. Because engine parts are well hidden from the pilots cookpit.
That's what I told it's little bit easy to debug java code.

i have seek answers for these problems but I didn't get any since years. But one thing is sure, debugger is to use when
the worse case secnario. When you have to use the debugger ,when the design is a fail. Otherwise use defensive
code techniques. Code that always checks preconditions , postconditions , lot the errors etc and mindful programming.
Simple self expressive code, ..etc.

And I'm agree with your C/C++ assembly thing. Most ppl believe that learning assembly is a waste. But Intel engineers
doesn't told like so. They told to drop out the older assemblers not assembly language knowledge. For a example
today fancy 3d games uses MMX/3D now instructions, the only way to use MMX SIMD instructions is go back to the inline assembly.
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: C++ And Other Problems

Post by Saman » Fri Aug 26, 2011 3:18 am

I do not agree with any point you mention as impossible to debug with C. May be you have used Visual C++ but I was talking about generic C/C++. Anyway keep my note, no C, no Java (I'm open to logical arguments). C++ has string exception handling just as in Java with Catch/Try blocks. Actually those are taken to Java directly from C++.

I have developed many application using C++ for many platforms. I rely on cross compilation due to efficiency than having them run on top of a slower JVM layer.
For a example today fancy 3d games uses MMX/3D now instructions, the only way to use MMX SIMD instructions is go back to the inline assembly.
MMX, SSE, 3D Now, etc... are usually used in professional application development such as games, scientific simulation, etc... with OpenGL or DirectX (both are written in C++/ASM).

If you have not read about nVIDIA CUDA yet, have a look at nVIDIA CUDA Resources. All the libraries related to CUDA is written in C/C++. CUDA is going to be the future of high performance computing.
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: C++ And Other Problems

Post by SemiconductorCat » Fri Aug 26, 2011 7:24 pm

thanks for the CUDA link.

what you mean by C++ in above post?I don't think that I get it.
I personally know developers who wote MMX inline instructions inside C++ directly.
Is now a easy method developed around this? Is that you tried to told? at that time
also there is a C++ preprocessed macros too. But not fancy like direct inline code.


and I didn't say it's impossible to debug C/C++, but I'm using gdb for debugging.
there are impossible places sometimes. what if there wasn't a debugger, in that
case you have in-circuit hardware debuggers. Have you seen intel developer boards
with these? still I can't put links, but I have seen that instrument in a MoU exhibition.


when you writing the code of a OS kernel , when the stages you setting GDT and IDT
(interrupt descriptor table) you don't have a debugger ! In that case I used Bochas
emulator as the debugger. Because I don't have money to buy a fancy hardware at all.
Bochas have a log window as well as a debug mode. enough for my purpose and also
works as a hardware debugger simulator. [hardware software simulator :p]
Image


I'm not a experienced developer but experienced developer told me that not to use
debugger as a tool. use it as an exception , debugger is the worst case scenario.
write mindful defensive code instead !
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: C++ And Other Problems

Post by Saman » Fri Aug 26, 2011 8:14 pm

what you mean by C++ in above post?I don't think that I get it.
I personally know developers who wote MMX inline instructions inside C++ directly.
Is now a easy method developed around this? Is that you tried to told? at that time
also there is a C++ preprocessed macros too. But not fancy like direct inline code.
I guess you are referring the following part. I was talking about C++ in many places in that post.
MMX, SSE, 3D Now, etc... are usually used in professional application development such as games, scientific simulation, etc... with OpenGL or DirectX (both are written in C++/ASM).
I just wanted to tell you that DirectX and OpenGL are written in C++.

However I have written codes FFTs, DCTs, IDCTs, FIR, IIRs, etc... in particular using MMX, SSE, 3DNow and some ARM instruction sets. Normally what we do is, we check the availability of most efficient instruction set on the host processor and execute as follows.

Code: Select all

If CPU_supports_SSE then
    FFT_sse();
else If CPU_supports_MMX then
    FFT_mmx();
else If CPU_supports_3DNow then
    FFT_3DNow();
else
    FFT_CPP(); // inefficient assembly version
end if
and I didn't say it's impossible to debug C/C++, but I'm using gdb for debugging.
there are impossible places sometimes. what if there wasn't a debugger, in that
case you have in-circuit hardware debuggers. Have you seen intel developer boards
with these? still I can't put links, but I have seen that instrument in a MoU exhibition.
What you are referring is IDE capabilities. Not the C++ again. Debugging is purely an IDE capability integrated with compiler. At compile time, based on your debug/warning level, the compiler puts special debug instructions to the compiled code. So you can put breakpoints, etc... in the code. If you compile your code without debug instructions, you will have the most compact code usually referred as release build.

Have you used Eclipse C++ IDE. This is very good and used in professional development across the planet. Eclipse also has a nice Java IDE. C++.Net on MS VS.Net is also very good. We use to to write little tools for us more often.

Finally, you were talking about the advantages of getting Java exceptions while running. Do you know those exceptions are thrown from JVM which is made using C++. (Just search in what language the Sun JVM had written). That's why I said, no C, no Java ;) (One thing for your note. When I say C, I refer C/C++... you know both are almost same except the OOP capabilities in C++ and few other little things).
when you writing the code of a OS kernel , when the stages you setting GDT and IDT
(interrupt descriptor table) you don't have a debugger ! In that case I used Bochas
emulator as the debugger. Because I don't have money to buy a fancy hardware at all.
Bochas have a log window as well as a debug mode. enough for my purpose and also
works as a hardware debugger simulator. [hardware software simulator :p]
I'm in to embedded platforms particularly ARM for many years now. We build our own OS with custom applications on top in C++/ASM. And we are fully capable of debugging it over hardware debuggers since we develop them on top of a host OS such as Linux or Windows. However if you are talking about building an OS such as Linux Kernel, your debugging capabilities are limited since it runs directly on the hardware. In these cases accurate programming, logging every step to a log file need to be used.

However in these cases, Java can't play any positive role. Anyway we already know that almost all popular OSs are made using C++/ASM just because the guys are not mad. They know what's the most close language to ASM. The more you close to ASM, the more you have control over your hardware.
I'm not a experienced developer but experienced developer told me that not to use
debugger as a tool. use it as an exception , debugger is the worst case scenario.
write mindful defensive code instead !
This is true. We were taught in the university to use pen and paper first before writing codes in the computer directly. Having a proper model on what you need to write, design it and finally code it using proper tools is the way.

I think we need to stop this argument now. This will never help to anybody other than confusing them ;)
(Just don't get yourself brain washed with anything... Just learn mathematics in parallel to programming. This is the combination that make a fully fledged programmer).
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: C++ And Other Problems

Post by SemiconductorCat » Fri Aug 26, 2011 11:53 pm

what we are doing is hijacking the original question, This is bad right!
but it's also bad if we didn't share each other's experience also.

I'll start another thread called "Share your debugging Tips offtopic thread"
where you me and others also can share their personal debugging nightmares and
how they overcome those.
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: C++ And Other Problems

Post by Nipuna » Sun Aug 28, 2011 8:13 pm

I don't mind hijacking :D
Post Reply

Return to “C/C++ Programming”