You are not logged in.

#51 2014-03-10 23:49:49

mmix
Member
Registered: 2014-01-11
Posts: 33

Re: C++ versus C: is C really "better"?

write http server in asm, because it gain performance,
BTW, current computer architecture fixed by big cpu company.
their assembly not good by design, see mill cpu.

Offline

#52 2014-03-12 00:15:30

anna
Member
Registered: 2014-01-08
Posts: 6

Re: C++ versus C: is C really "better"?

In the end it's all about preference.  I use both regularly, and I've found that I prefer C++ for my own projects mostly because of the STL.  The code I write for my job is all in C.  The programming concepts are all the same and you can use a combination of structs and function pointers if you need objects to pass around.

Offline

#53 2014-03-12 07:37:10

007
Member
From: /dev/shm
Registered: 2012-08-15
Posts: 21

Re: C++ versus C: is C really "better"?

Gregosky wrote:

Oh, and I know people who write everything in ASM (yes, GUI applications too). So paraphrasing for some people it seems it's not impossible to use screwdriver to build a car :-)

Professionally? Embedded? What kind of applications? Do they have a Github?

Offline

#54 2014-03-12 18:42:59

Gregosky
Member
From: UK
Registered: 2013-07-26
Posts: 174

Re: C++ versus C: is C really "better"?

007 wrote:
Gregosky wrote:

Oh, and I know people who write everything in ASM (yes, GUI applications too). So paraphrasing for some people it seems it's not impossible to use screwdriver to build a car :-)

Professionally? Embedded? What kind of applications? Do they have a Github?

Nobody would want running their business applications development with ASM unless it's the right tool. My good friend who does use ASM for building GUI applications does it in his own time for his own satisfaction.

Offline

#55 2014-03-21 13:46:44

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,362

Re: C++ versus C: is C really "better"?

Of course you can asm block inside your C program. 
Anyhow, I've never quite gotten to the point where I've actually used the polymorphism function of C++.  I'm sure it's nice and it has it's place, but calling the same name function because it's in the same derived class and virtualized allows this to happen.  Was this by design or a necessity?  Sometimes this sort of this thing seems to need much trouble to go to actually use it, but it must've been needed at some point to make things easier.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#56 2014-03-21 15:45:44

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,774

Re: C++ versus C: is C really "better"?

nomorewindows wrote:

...I've never quite gotten to the point where I've actually used the polymorphism function of C++.  I'm sure it's nice and it has it's place, but calling the same name function because it's in the same derived class and virtualized allows this to happen.  Was this by design or a necessity?

Actually, you are describing overriding of functions, not polymorphism. 

Overriding a function means you want a different behavior than that provided by the base class. 
Polymorphism means using the same function name, but having the actual code that is invoked be controlled by the arguments and their types.

Overriding:  Perhaps you save a base class, shape.  Sub classes might be circle, square, triangle.   Shape might have a purely virtual function, area.  You must override it.  Each of the sub classes would define area and override the base class.  If the base class is not purely virtual, then it does not need to be overriden and might return some default behavior.  That does not make sense in this case.

polymorphism:  You might define 'add' in a base class.  It works  for two integers.  Define 'add' in a sub class, it allows you to add two floats.  Define it again in the sub class, but this time have the arguments be add and and integer.

In use, you could define i and j as ints.  f and g as floats.  add(a,b); add(f,g) and add(a,f) would each call the appropriate function you have defined based upon the arg list.


Edit:  Okay, so I see by poking around the net that some people do consider overriding of virtual functions by sub classes to be a form of polymorhism.  I tend to keep it as a separate concept.

Last edited by ewaller (2014-03-21 16:11:12)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#57 2014-03-21 19:35:06

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: C++ versus C: is C really "better"?

@ewaller: in OOP, the term polymorphism is almost exclusively used to refer to subtyping/inclusion polymorphism (and overriding virtual methods is an important part of that); so it's a bit like the thing that you tend to keep as a separate concept is the only concept that many programmers know as polymorphism hmm

What you call polymorphism in your 'add' example is usually just called (function) overloading, but you're right that it is also a kind of polymorphism, namely ad hoc polymorphism. Similarly, what is often only known as generics (e.g. in Java; C++ allows the same (and more) with templates) is yet another kind of polymorphism: parametric polymorphism.

Edit: I just checked my C++ Primer (4th edition). Polymorphism is indeed explained in the subtyping sense, but they do mention later on that templates also provide a form of polymorphism. I can't find the word 'polymorphism' anywhere in relation to overloaded methods and other tutorials (also for other languages) I've seen are no different.

(This thread does seem to have drifted off topic somewhat, but in this case it has made the thread more interesting IMO; I had almost forgotten about rust and go.)

Last edited by Raynman (2014-03-21 19:47:58)

Offline

#58 2014-03-21 20:12:26

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,362

Re: C++ versus C: is C really "better"?

The type function is pretty basic, even can be used in basic C, but that was called demangling.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#59 2014-03-22 00:31:51

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: C++ versus C: is C really "better"?

nomorewindows wrote:

The type function is pretty basic, even can be used in basic C, but that was called demangling.

I encourage you to rephrase that, both to make it clear what you're talking about (C has no function called "type") and to make clear how it's relevant to the topic (what does demangling have to do with... anything?)

Offline

#60 2014-03-22 00:46:26

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,362

Re: C++ versus C: is C really "better"?

Trent wrote:
nomorewindows wrote:

The type function is pretty basic, even can be used in basic C, but that was called demangling.

I encourage you to rephrase that, both to make it clear what you're talking about (C has no function called "type") and to make clear how it's relevant to the topic (what does demangling have to do with... anything?)

When you have two or functions with different parameters func(a) vs func (a,b) the underwritten parts distinguish between the two functions based on the function call and the data types passed as parameters to not be the same function but different functions so that it can differentiate them at compile or run time.  The process of it doing that was called demangling.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#61 2014-03-22 01:27:41

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: C++ versus C: is C really "better"?

I know what demangling is. I was asking what you were saying about C, which has no use for demangling (as it doesn't allow function overloading and therefore has no obvious reason to mangle function names). I'm also wondering what you meant by "[t]he type function", since I've never heard of anything by that name in C. (Perhaps you're thinking of the typeof operator, which is a GCC extension.)

Offline

#62 2014-03-22 11:22:44

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,362

Re: C++ versus C: is C really "better"?

Trent wrote:

I know what demangling is. I was asking what you were saying about C, which has no use for demangling (as it doesn't allow function overloading and therefore has no obvious reason to mangle function names). I'm also wondering what you meant by "[t]he type function", since I've never heard of anything by that name in C. (Perhaps you're thinking of the typeof operator, which is a GCC extension.)

Maybe you're right.   Probably wouldn't compile if I tried that in C would it?  I've become accustomed to her face (oops that's the name of a song), to using for loops before C++ standardized and I have to switch from gcc to g++ (or gcc --std=c98)  to compile such a program. 
There was also the typedef function similar to the later macro function.

Last edited by nomorewindows (2014-03-22 11:30:05)


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#63 2014-07-15 04:23:46

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: C++ versus C: is C really "better"?

I've recently stumbled upon Go. It seems like a good compromise between efficiency and modern conventions, and it is strongly based in C/C++. I'll probably study it during the next weeks. Has anyone tried it?

Offline

#64 2014-07-15 07:59:32

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: C++ versus C: is C really "better"?

thiagowfx wrote:

Has anyone tried it?

I'm not a dev, but here are some project written in go:
https://wiki.archlinux.org/index.php/Wingo
https://bbs.archlinux.org/viewtopic.php?id=183956


https://github.com/trending?l=go

Offline

#65 2014-07-15 12:26:11

anatolik
Developer
Registered: 2012-09-27
Posts: 458

Re: C++ versus C: is C really "better"?

007 wrote:
Gregosky wrote:

Oh, and I know people who write everything in ASM (yes, GUI applications too). So paraphrasing for some people it seems it's not impossible to use screwdriver to build a car :-)

Professionally? Embedded? What kind of applications? Do they have a Github?

I know several large opensource projects that use asm.
http://www.menuetos.net/ (and yes GUI is also implemented in asm)
http://www.returninfinity.com/


Read it before posting http://www.catb.org/esr/faqs/smart-questions.html
Ruby gems repository done right https://bbs.archlinux.org/viewtopic.php?id=182729
Fast initramfs generator with security in mind https://wiki.archlinux.org/index.php/Booster

Offline

#66 2014-07-15 22:47:04

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: C++ versus C: is C really "better"?

Thanks for your links, karol. It looks like wingo is worth a try.

Offline

#67 2014-07-16 15:27:25

publicus
Member
Registered: 2014-01-01
Posts: 129

Re: C++ versus C: is C really "better"?

JohnnyDeacon wrote:

I'm not an expert for this themes, but I think you can't compare C with C++ in fact C++ is a major release of C but with classes. C is an imperative (procedural) language, it means, you only can construct programs by functions. C++ has all of this, but adds classes (new data type) that can create software by creating templates, like real life. In fact, that was the final purpose of its developers. Make programs like you cooking for example. I better prefer that someone else that works with programming tell us the real differences, but I'm little sure that C is for hardware interactions developments Like Linux Core and C++ for general purposing.

If you look at just about any modern and relatively popular programming language, you can -- usually, but not always -- simulate certain paradigms in that language for which it was not designed to handle.  However, this is usually more work and not really worth it.  Sort of similar trying to unscrew a bolt with a hammer...

I can simulate object oriented design in C and Erlang, but that's like putting out a fire by dousing it with water from a tablespoon at a time.

Offline

#68 2014-07-17 21:12:41

Asmir
Member
From: BiH
Registered: 2011-10-06
Posts: 67

Re: C++ versus C: is C really "better"?

Maybe not so much comparable things since C and C++ are two different languages shring similar syntax ( and I hate it when people compile C  source with C++ compiler ) but I think of C++   as kinda broken.
Why?
C++ was meant to expand C by OOP and keep the syntax and functionality of C, but, now the C part and the OOP part don't go together, for example you can not use objects in switch statements, you can not use fprintf() with streams or intialize a vector like std::vector<int> a = { 1, 2 };

I also don't like this pseudo generic programming where compiler writes code for me, though templates are not a bad thing.
For performance part, OOP makes it easy to write code with high CPU cache misses.

Btw: did you know that in C++ 'a' is of type char and in C it's an int. big_smile

Offline

#69 2014-07-17 22:21:25

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: C++ versus C: is C really "better"?

Asmir wrote:

or intialize a vector like std::vector<int> a = { 1, 2 };

In C++11 you can.

Offline

#70 2014-07-18 11:25:08

Asmir
Member
From: BiH
Registered: 2011-10-06
Posts: 67

Re: C++ versus C: is C really "better"?

thiagowfx wrote:
Asmir wrote:

or intialize a vector like std::vector<int> a = { 1, 2 };

In C++11 you can.

Thats wise from them, I think I shluld take some time to check out C++11, I've heard they experiment with lambda calculus too. smile

Offline

#71 2014-07-18 12:19:18

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: C++ versus C: is C really "better"?

I feel like adding lambda expressions to C++11 is too little, too late if it was even a good idea in the first place -- maybe true for Java 8 too. What do people currently use C++ for where lambdas would be a big improvement? Or is this a halfhearted attempt to make C++ more relevant in areas where it's losing to higher level languages? It'll take a lot more than lambdas to make C++ an attractive alternative to Python, Ruby or Javascript.

Offline

#72 2014-07-18 14:43:53

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,774

Re: C++ versus C: is C really "better"?

Trent wrote:

... It'll take a lot more than lambdas to make C++ an attractive alternative to Python, Ruby or Javascript.

That is a pretty broad brush.  Ever developed code that is safety critical? I'm talking life support, flight controls, or weapons authority?  I don't even know where one would start to prove the behavior of code written in those languages is deterministic.  Obviously, these are corner cases, but they are exceptions to your assertion.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#73 2014-07-18 18:29:03

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: C++ versus C: is C really "better"?

ewaller wrote:
Trent wrote:

... It'll take a lot more than lambdas to make C++ an attractive alternative to Python, Ruby or Javascript.

That is a pretty broad brush.  Ever developed code that is safety critical? I'm talking life support, flight controls, or weapons authority?  I don't even know where one would start to prove the behavior of code written in those languages is deterministic.  Obviously, these are corner cases, but they are exceptions to your assertion.

You snipped

Trent wrote:

in areas where it's losing to higher level languages

which is what the part you quoted was referring to, although I admit that wasn't very clear.

That said, correct me if I'm wrong, but isn't code that must be formally verified usually written in a restricted subset of the entire C++ language? Lambdas probably won't be making it into MISRA C++ any time soon.

Last edited by Trent (2014-07-18 18:29:26)

Offline

#74 2014-07-18 19:21:23

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,774

Re: C++ versus C: is C really "better"?

Trent wrote:

You snipped

Trent wrote:

in areas where it's losing to higher level languages

which is what the part you quoted was referring to, although I admit that wasn't very clear.

In re-reading the thread, yes, I agree.

That said, correct me if I'm wrong, but isn't code that must be formally verified usually written in a restricted subset of the entire C++ language? Lambdas probably won't be making it into MISRA C++ any time soon.

To be honest, I have not done anything with life support.  Flight code was actually written in C


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#75 2014-08-26 14:21:07

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,362

Re: C++ versus C: is C really "better"?


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

Board footer

Powered by FluxBB