MAMEWorld >> EmuChat
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Pages: 1

mike20599
MAME Fan
Reged: 09/14/08
Posts: 247
Send PM


Should I learn C or C++?
#282870 - 04/17/12 12:30 AM


Hi smart computer people! There is a local community college offering a course in C this summer and C++ later in the fall. Which one should I take? Both? Which would be better for a hobbyist programmer? What about in the job market? I don't have much programming experience at all. I know a little HTML, a little javascript, and a little PHP. Oh and a little BASIC from back in the day.



Sune
Connected
Reged: 09/21/03
Posts: 5648
Loc: Lagoa Santa, Brasil
Send PM


Re: Should I learn C or C++? new [Re: mike20599]
#282873 - 04/17/12 12:40 AM


> Hi smart computer people! There is a local community college offering a course in C
> this summer and C++ later in the fall. Which one should I take? Both?

Both, then decide which one appeals to you the most.

S



CTOJAH
MAME Addict
Reged: 07/13/10
Posts: 980
Loc: Macedonia,Veles
Send PM


Re: Should I learn C or C++? new [Re: mike20599]
#282875 - 04/17/12 12:43 AM


If You wanna be a programmer You should always be up-to-date... ...so Cee Plus Plus is the right tool for You.
Anyway, in old good days, hobbyist programmers used Assembler (machine code) for best results. Those were the days of C64, Spectrum, Amiga, Atari ST... Machine code is the lowest level "programming language", but also the fastest one - which reminds me to ask :
Wouldn't the MAME emulator be more accurate (and faster regarding Naomi/Atomiswave, Model 3 and other newer systems...) if it was written in assembler ?



Sune
Connected
Reged: 09/21/03
Posts: 5648
Loc: Lagoa Santa, Brasil
Send PM


Re: Should I learn C or C++? new [Re: CTOJAH]
#282883 - 04/17/12 01:34 AM


> Wouldn't the MAME emulator be more accurate (and faster regarding Naomi/Atomiswave,
> Model 3 and other newer systems...) if it was written in assembler ?

If MAME was written in x86 assembler it would be a lot less portable/cross platform.

S



Bryan Ischo
MAME Fan
Reged: 03/28/10
Posts: 358
Send PM


Re: Should I learn C or C++? new [Re: CTOJAH]
#282884 - 04/17/12 01:35 AM


> Wouldn't the MAME emulator be more accurate (and faster regarding Naomi/Atomiswave,
> Model 3 and other newer systems...) if it was written in assembler ?

Yes, but such a thing could never exist, because nobody would write such a complex piece of software entirely in assembler.

You might as well ask, wouldn't MAME run faster if the entire GDP of the USA had been devoted to making it as fast as possible for the last 10 years?

The answer is yes, but that is a hypothetical situation that could never practically happen.



Bryan Ischo
MAME Fan
Reged: 03/28/10
Posts: 358
Send PM


Re: Should I learn C or C++? new [Re: mike20599]
#282885 - 04/17/12 01:37 AM


> Hi smart computer people! There is a local community college offering a course in C
> this summer and C++ later in the fall. Which one should I take? Both? Which would be
> better for a hobbyist programmer? What about in the job market? I don't have much
> programming experience at all. I know a little HTML, a little javascript, and a
> little PHP. Oh and a little BASIC from back in the day.

In my experience, C++ goes alot further on job applications than C does, for what it's worth. Also, C is more or less a subset of C++ so if you know C++, it won't take long to get used to writing/reading C code; whereas knowing C doesn't even get you close to writing/reading C++ code.

I would take C++, but keep in mind that you will never be an expert after a single class ... or even 5 years of work experience for that matter.

Edited by Bryan Ischo (04/17/12 01:40 AM)



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Should I learn C or C++? new [Re: CTOJAH]
#282895 - 04/17/12 02:31 AM


> Wouldn't the MAME emulator be more accurate (and faster regarding Naomi/Atomiswave,
> Model 3 and other newer systems...) if it was written in assembler ?

No. Demul and Makaron (and NullDC, and ElSemi's Model 2 emulator, and SuperModel) are written in C++. And you'd agree it hasn't hurt them, right?



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Should I learn C or C++? new [Re: Bryan Ischo]
#282896 - 04/17/12 02:33 AM


> > Wouldn't the MAME emulator be more accurate (and faster regarding Naomi/Atomiswave,
> > Model 3 and other newer systems...) if it was written in assembler ?
>
> Yes, but such a thing could never exist, because nobody would write such a complex
> piece of software entirely in assembler.

I would submit that the answer is actually "no". Accuracy would plummet due to the complexity of writing a Naomi emulation entirely in assembly, and if the same exact algorithms were used (e.g. an interpreter SH-4 core and a PowerVR drawing routine that piped each pixel through MAME's memory system) you would get identically absymal performance.



CTOJAH
MAME Addict
Reged: 07/13/10
Posts: 980
Loc: Macedonia,Veles
Send PM


Re: Should I learn C or C++? new [Re: R. Belmont]
#282898 - 04/17/12 02:51 AM


R. Belmont said :
No. Demul and Makaron (and NullDC, and ElSemi's Model 2 emulator, and SuperModel) are written in C++. And you'd agree it hasn't hurt them, right?

When those emulators/programs have been compiled from their source codes, the final result is actually machine code (assembler). When I asked about speed and accuracy of assembler, I was thinking of optimised code for each machine/computer respectively. Compiling from C++ You won't be able to get .exe, which will be well structured algorithm as if You programmed the whole thing in assem. from scratch.
Todays PCs are too much faster then Sega/Sammy arcade machines, therefore programming in C++, even in JAVA is fast enough to emulate those systems... ...so I am happy with Demul and SuperModel



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Should I learn C or C++? new [Re: CTOJAH]
#282916 - 04/17/12 04:18 AM


> R. Belmont said :
> No. Demul and Makaron (and NullDC, and ElSemi's Model 2 emulator, and SuperModel) are
> written in C++. And you'd agree it hasn't hurt them, right?
>
> When those emulators/programs have been compiled from their source codes, the final
> result is actually machine code (assembler).

And that's equally true of MAME.

> Compiling from C++ You won't be able to get .exe, which will be well structured
> algorithm as if You programmed the whole thing in assem. from scratch.

What? Compiling from C++ produces an .exe file. mame.exe, demul.exe, supermodel.exe.

Here's the magic experiment I always tell people: load Demul and set it to use the interpreter CPU (MAME currently uses an interpreter for the SH-4). You will then get the same performance as MAME. Algorithms trump implementation details, every single time.



DMala
Sleep is overrated
Reged: 05/09/05
Posts: 3989
Loc: Waltham, MA
Send PM


Re: Should I learn C or C++? new [Re: R. Belmont]
#282931 - 04/17/12 04:58 AM


> > Compiling from C++ You won't be able to get .exe, which will be well structured
> > algorithm as if You programmed the whole thing in assem. from scratch.
>
> What? Compiling from C++ produces an .exe file. mame.exe, demul.exe, supermodel.exe.

I think he's saying that hand-coded assembly is more efficient than that generated by a C++ compiler. Which was true, kind of, once upon a time.



mogli
MAME Fan
Reged: 01/26/08
Posts: 1956
Send PM


Re: Should I learn C or C++? new [Re: DMala]
#282944 - 04/17/12 05:29 AM


> > > Compiling from C++ You won't be able to get .exe, which will be well structured
> > > algorithm as if You programmed the whole thing in assem. from scratch.
> >
> > What? Compiling from C++ produces an .exe file. mame.exe, demul.exe,
> supermodel.exe.
>
> I think he's saying that hand-coded assembly is more efficient than that generated by
> a C++ compiler. Which was true, kind of, once upon a time.

For more on this, CTO, read here, and every post of his in the thread.



Consider it high comedy....sincere tragedy....whatever...don't take it personally.

The Culture




Anonymous
Unregistered
Send PM


Re: Should I learn C or C++? new [Re: DMala]
#282962 - 04/17/12 08:41 AM


> I think he's saying that hand-coded assembly is more efficient than that generated by
> a C++ compiler. Which was true, kind of, once upon a time.

It's still true. You could write a C++ program, compile it and find some optimisations that the compiler didn't.

The only downside is you'll spend a very long time searching for a very small performance gain. Time that could be better spent working on other ways of speeding it up.

With a C++ program of MAME's complexity you'll still be going when faster processors can run the C++ version fast enough.

There are very (very) rare circumstances when you have an algorithm that can't be improved, hardware that can't be upgraded and an absolute requirement for performance. In these circumstances it can be worth dropping to assembler. Anyone who thinks they've come across one of these circumstances before was probably wrong and there was a cheaper way.

Edited by smf (04/17/12 08:41 AM)



Anonymous
Unregistered
Send PM


Re: Should I learn C or C++? new [Re: R. Belmont]
#282964 - 04/17/12 08:54 AM


> I would submit that the answer is actually "no". Accuracy would plummet due to the
> complexity of writing a Naomi emulation entirely in assembly, and if the same exact
> algorithms were used (e.g. an interpreter SH-4 core and a PowerVR drawing routine
> that piped each pixel through MAME's memory system) you would get identically absymal
> performance.

The answer is no. I disagree on your reasoning though.

It would certainly be harder to write in assembler. It would be possible to match or exceed MAME's current accuracy with a version written in assembler. However in this very unlikely situation it wouldn't be assembler that helped. You could improve the accuracy much easier by improving the current code (even if you threw it all out and started again).

You probably wouldn't have time to work or sleep as Intel & AMD are likely to have released hardware that dwarfs your optimisations before you finish.



Quantum Leaper
OCRer and Monkey Typist for Galaxy Game
Reged: 03/08/04
Posts: 198
Loc: Orion spiral arm of the Milky Way
Send PM


Re: Should I learn C or C++? new [Re: Sune]
#282971 - 04/17/12 12:42 PM


> > Hi smart computer people! There is a local community college offering a course in C
> > this summer and C++ later in the fall. Which one should I take? Both?
>
> Both, then decide which one appeals to you the most.
>
I agree, both, more programming languages the better, who wants a carpenter that only know how to use a hammer? I learned C first, it made C++ fairly easy. Community Colleges class are fairly easy to begin with, at least compared to a 4 year College or University.



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Should I learn C or C++? new [Re: ]
#282980 - 04/17/12 02:31 PM


> The answer is no. I disagree on your reasoning though.
>
> It would certainly be harder to write in assembler. It would be possible to match or
> exceed MAME's current accuracy with a version written in assembler. However in this
> very unlikely situation it wouldn't be assembler that helped

Right. My point was that assembler would hurt simply because it's an order of magnitude more time-intensive to write and debug.

> You probably wouldn't have time to work or sleep as Intel & AMD are likely to have
> released hardware that dwarfs your optimisations before you finish.

That's less likely now than it was when we started MAME (only nutters like myself commonly run machines over 4 GHz) but we're slowly learning to take advantage of multicore. The real issue is these modern CPUs are so smart about reworking your code "live" for optimization that hand-tuning is mostly irrelevant.



Anonymous
Unregistered
Send PM


Re: Should I learn C or C++? new [Re: R. Belmont]
#283043 - 04/17/12 11:16 PM


> Right. My point was that assembler would hurt simply because it's an order of
> magnitude more time-intensive to write and debug.

It will certainly make it harder to write, but it would be wrong to suggest that language choice has some magic ability to make an emulator more accurate.

> That's less likely now than it was when we started MAME (only nutters like myself
> commonly run machines over 4 GHz) but we're slowly learning to take advantage of
> multicore.

It will be interesting to see what comes in another ten years, but currently there doesn't look like they'll be the same jump in performance that we have had since the 486 days.

> The real issue is these modern CPUs are so smart about reworking your code
> "live" for optimization that hand-tuning is mostly irrelevant.

They've hit the same problem, it's now hard to just ramp the clock speed so they are having to find better algorithms to make code run faster. As there is a lot of C++ code out there then I'd expect to see improvements in compilers and the processors ability to run the generated code faster. Which of course you also don't get the benefit if you write in assembler.



Anonymous
Unregistered
Send PM


Re: Should I learn C or C++? new [Re: Quantum Leaper]
#283044 - 04/17/12 11:18 PM


> I learned C first, it made C++ fairly easy.

I went C -> C# -> C++

So I find C++ a little weird & still prefer C#



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Should I learn C or C++? new [Re: ]
#283092 - 04/18/12 03:27 PM


> They've hit the same problem, it's now hard to just ramp the clock speed so they are
> having to find better algorithms to make code run faster. As there is a lot of C++
> code out there then I'd expect to see improvements in compilers and the processors
> ability to run the generated code faster. Which of course you also don't get the
> benefit if you write in assembler.

Agreed. And it's nice that there's competition in compilers again, too. Microsoft is touting "native development" as a feature for VC++ 11, and there's some pretty radical plans for GCC 5.0 in response to Clang starting to eat their lunch.


Pages: 1

MAMEWorld >> EmuChat
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Robbbert, Tafoid 
0 registered and 272 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 1337