EvilZone
Programming and Scripting => C - C++ => Topic started by: lucid on March 06, 2013, 01:31:56 AM
-
What's better for coding, say, a server. Like a SOCKS server. C or C++? I'm guessing C and that makes me sad. See, right now I'm learning PHP/MySQL. I'm determined to stick with it because I've bounced around too much in the past year and I haven't gotten anywhere. But my ultimate desire is to learn C. In about 6 months I'm going to be taking programming classes and AFAIK they will be involving C++. I've often heard it's a bad idea to try to learn two languages at once and I REALLY wanted to focus on C after focusing on PHP/MySQL for the next 6 months but now it appears I'll be forced to learn C++. Not that that's a bad thing I had wanted to learn that eventually too, so if I took the class I would want to learn it but I wanted to learn C first..
I'm going in circles you get my point.
-
Well just like the name suggests C++ is meant to be supersede C. Most C code can be complied and run perfectly in C++ while the reverse isn't true, so learning C++ isn't that bad, and is quite possibly an advantage. C is sometimes seen as a low level programming language and is faster than C++ which is why there are a lot of drivers are written in C. and C++ supports OOP and is in my opinion easier to understand than C. So i think transferring from C++ to C wont really be that much of a challenge.
-
What's better for coding, say, a server. Like a SOCKS server. C or C++?
That really doesn't matter. It is more important if you prefer to use OOP and other stuff that C doesn't have.
I'm guessing C and that makes me sad. See, right now I'm learning PHP/MySQL. I'm determined to stick with it because I've bounced around too much in the past year and I haven't gotten anywhere. But my ultimate desire is to learn C. In about 6 months I'm going to be taking programming classes and AFAIK they will be involving C++. I've often heard it's a bad idea to try to learn two languages at once and I REALLY wanted to focus on C after focusing on PHP/MySQL for the next 6 months but now it appears I'll be forced to learn C++. Not that that's a bad thing I had wanted to learn that eventually too, so if I took the class I would want to learn it but I wanted to learn C first..
I'm going in circles you get my point.
If learning C is your ultimate desire, why do you do PHP?
Is it really that bad, to learn C++ first? You can transfer a lot of that knowledge to C.
I don't really see your problem.
Sorry, but I can't help it: :P
(http://cdn.memegenerator.net/instances/400x/35762805.jpg)
@Super_mario666
Explain why C should be faster than C++. That doesn't make any sense to me, because you already said:
Most C code can be complied and run perfectly in C++
-
@Super_mario666
Explain why C should be faster than C++. That doesn't make any sense to me, because you already said:
Most C code can be complied and run perfectly in C++
Dont get me wrong its not a substantial difference and by C, i meant C libraries. from my own experience with them i generally found C-based libraries (such as stdio.h) to be little faster the C++ libraries(such as iostream). and AFAIK a large number of drivers are mostly written in C.
-
I personally studied C++ as a first programming language, and then followed up with C, PHP, SQL,low-level ASM, Java (in that order) and I found it to be quite easy to understand. Sure, I did fail exams for some the courses, but then again who the hell doesn't.
The important thing is that I personally feel I have a better-than-average grasp of all these languages, I'm not afraid to take on projects/tasks that involve programming with this, and I think this is mostly caused by the order in which I took them. C++ was very easy to understand and to help me get the basics of wtf is happening with programming, and I found C to be as well quite easy after knowing all the other stuff.
Of course your results may vary, but just my 2c here.
-
That really doesn't matter. It is more important if you prefer to use OOP and other stuff that C doesn't have.
If learning C is your ultimate desire, why do you do PHP?
Is it really that bad, to learn C++ first? You can transfer a lot of that knowledge to C.
I don't really see your problem.
Sorry, but I can't help it: :P
(http://cdn.memegenerator.net/instances/400x/35762805.jpg)
@Super_mario666
Explain why C should be faster than C++. That doesn't make any sense to me, because you already said:
I want to stick with PHP and MySQL mainly because I wanted an actual understanding of SQL injections work instead of taking the skid approach and just learning common SQL injection syntax, and the two languages are practically inseparable in my opinion. Plus I've already started learning PHP and I can't keep jumping between languages without actually learning anything. I plan to learn PHP/MySQL over the next six months until I start my programming classes.
-
I want to stick with PHP and MySQL mainly because I wanted an actual understanding of SQL injections work instead of taking the skid approach and just learning common SQL injection syntax, and the two languages are practically inseparable in my opinion. Plus I've already started learning PHP and I can't keep jumping between languages without actually learning anything. I plan to learn PHP/MySQL over the next six months until I start my programming classes.
Sounds reasonable.
I see your problem, but there is not much you can do. Just be patient. Everything you learn has a value. You don't do it for nothing.
-
I suppose you're right. The only reason I asked about coding a server by the way is because I know C is more for drivers and such and C++ more for games and whatnot, and I really have no interest in coding game-related stuff.
EDIT: Ok one last question. Sorry it's kind of a noob one. I just want to know how long I'm going to have to wait to learn C. Because goddamnit I want to learn more low-level shit. My ultimate ultimate goal is to learn ASM. So when I started C I had planned to very slowly learn a little ASM along side it, like debugging and disassembling my own programs and shit.
-
I suppose you're right. The only reason I asked about coding a server by the way is because I know C is more for drivers and such and C++ more for games and whatnot, and I really have no interest in coding game-related stuff.
EDIT: Ok one last question. Sorry it's kind of a noob one. I just want to know how long I'm going to have to wait to learn C. Because goddamnit I want to learn more low-level shit. My ultimate ultimate goal is to learn ASM. So when I started C I had planned to very slowly learn a little ASM along side it, like debugging and disassembling my own programs and shit.
3 months to learn basic syntax, 2 more months to learn OOP(you could skip this cause C isnt OOP) and the Standard Template Library. after that transferring to C would take about 2-4 weeks although i really think you should stick with C++. I personally dont know long it will take to learn the low level stuff. i think learning ASM would be a living hell but once you do, i think you would make a really badass cracker :D
-
I suppose so. I mean, it's not like I wasn't planning on learning C++ at some point, I just wanted to do C first because I hear it's a better idea. Oh well, I guess there's nothing I can do. I guess I could learn C++ through all the classes I'm going to take and then when I'm done I can switch to C and ASM.
Cool.
-
What's better for coding, say, a server. Like a SOCKS server. C or C++? I'm guessing C and that makes me sad. See, right now I'm learning PHP/MySQL. I'm determined to stick with it because I've bounced around too much in the past year and I haven't gotten anywhere. But my ultimate desire is to learn C. In about 6 months I'm going to be taking programming classes and AFAIK they will be involving C++. I've often heard it's a bad idea to try to learn two languages at once and I REALLY wanted to focus on C after focusing on PHP/MySQL for the next 6 months but now it appears I'll be forced to learn C++. Not that that's a bad thing I had wanted to learn that eventually too, so if I took the class I would want to learn it but I wanted to learn C first..
I'm going in circles you get my point.
A server, including a SOCKS server, could be created in either language. Technically C++ would make certain things potentially much easier, depending on the service for which you're coding. Please keep in mind that sockets are still typically C-based and whilst there do exist pure-C++ impelementations, they're rarely used and almost never taught/permitted in classes.
Whilst I believe it best to learn C before C++, thousands of people have taken alternate routes and turned out just fine. Some elements may be a little more difficult to wrap your head around during the first iteration or two but it certainly doesn't make it impossible or even a 'bad' thing to learn C++ first.
I strongly recommend that you take the time to fully understand what it is that you're doing. When learning C++, take some extra time to learn a few of the details(though, no need to overload yourself) so that you can get a grasp of how and why it works. What you should be after, ultimately, is knowing the language well enough to predict how the computer will react to the statements that you input BEFORE actually asking the computer to do it(e.g. before compilation).
Well just like the name suggests C++ is meant to be supersede C.
Woah. Let me stop you right there for a second. Perhaps this was not the intention, but the term 'supercede' indicates the obsoletion of something. In this case, the statement denotes that with the invention of C++, C is obsolete. I assure you, such is most certainly NOT the case.
Perhaps, instead, you mean that C++ is a 'superset' of C. In a way, this is far more correct. Essentially, you take the C language and add a bunch of features to it to create additional language elements, syntax, constructs, etc. that provide a better 'fit' for certain applications(meaning 'uses', not 'programs'). This term fits C++ very well though it is not quite enough. C++ is indeed an independent language in its own right. This is evident in some ways with the addition of function overloading, the creation of vtables to support such a feature, and the resultant generated object code.
Most C code can be complied and run perfectly in C++ while the reverse isn't true, so learning C++ isn't that bad, and is quite possibly an advantage.
A C++ compiler can usually compile C code. The advantage is in the use of the C++ compiler, not in the language(not with this statement, anyway). If I were to create an interpreter that could interpret both Perl and Python code, it may be an advantage for my program..but not for 1 language or the other.
C is sometimes seen as a low level programming language and is faster than C++ which is why there are a lot of drivers are written in C. and C++ supports OOP and is in my opinion easier to understand than C. So i think transferring from C++ to C wont really be that much of a challenge.
C is not low-level. I admit that people these days do 'see' it as low-level, but it isn't. As for its speed; it really depends on what you're doing with the code. There are several instances where C++ actually performs faster than equally-optimized C. GCC 4.8 marks a full switch to C++ from C(meaning the compiler itself is now coded in C++) and benefits from a few performance enhancements as a result. Intel's C & C++ compiler have been C++-based for years and, whilst its own compilation speed may not be that fantastic by comparison, can produce very heavily optimized executables. C++ allows these compilers to use additional features in different ways to analyze code and apply optimizations in manners more difficult to do in C. Of course, this is not to say that it couldn't be done in C; only that, with the additional features, it is easier in C++.
I want to stick with PHP and MySQL mainly because I wanted an actual understanding of SQL injections work instead of taking the skid approach and just learning common SQL injection syntax, and the two languages are practically inseparable in my opinion. Plus I've already started learning PHP and I can't keep jumping between languages without actually learning anything. I plan to learn PHP/MySQL over the next six months until I start my programming classes.
If I am to understand this... Do you see C++ as taking a 'skid' approach? Perhaps because certain things may be easier in C++ than C? If this is so, please don't confuse 'difficult' with 'better'. Using Gentoo doesn't make one a more 'hardcore' Linux user(only, hopefully, a more patient one). Just because something is easier doesn't mean that it's a shortcut or excuse or some cheap way out.
Sounds reasonable.
I see your problem, but there is not much you can do. Just be patient. Everything you learn has a value. You don't do it for nothing.
Indeed; everything you learn has a value. Deque, you are fast becoming one of my favourite members.
I suppose you're right. The only reason I asked about coding a server by the way is because I know C is more for drivers and such and C++ more for games and whatnot, and I really have no interest in coding game-related stuff.
C is not necessarily more for drivers. C may be used more often for drivers than C++ but that is not necessarily because the language is better suited for the task. Of all the different operating systems that exist in the world, the vast majority of them are C-based. Some of this is because the code base existed prior to the popularization of C++. With C-based operating systems usually comes C-coded kernels and system libraries supporting a minimum C 'standard'(even if it's not fully 'standards-compliant'). This means that you are more likely to have an easier time coding something in C than in C++ as services for C++ may not be available within the lower levels of the OS code. Of course, once you create your own 'essential' OS component in C, you more or less force others that use it to also code in C. Thus, such a trend becomes de facto.
As for C++ being "for games". I think you can understand the error in the statement. Again, the language may more often be used for such a thing but that doesn't mean that there's any limitation either with the game field nor with the languages used. C++ has enjoyed much success in many areas, including servers. For example, InspIRCd is quickly becoming one of the most popular IRCd's available and it is written, to its core, in C++. There are webservers, mailservers, authentication systems, etc. that are all coded in C++. Whilst the C-based ones may be more popular and more common, it is not either language's fault.
EDIT: Ok one last question. Sorry it's kind of a noob one. I just want to know how long I'm going to have to wait to learn C. Because goddamnit I want to learn more low-level shit. My ultimate ultimate goal is to learn ASM. So when I started C I had planned to very slowly learn a little ASM along side it, like debugging and disassembling my own programs and shit.
I don't advise learning ASM along side C. ASM isn't really that 'difficult', per se, but it is certainly different. ASM will introduce quickly concepts that are likely to confuse someone who is just beginning in C. If you are already well familiar with ASM, it poses an advantage to learning certain parts of C. If you're already well familiar with C, learning ASM is merely understanding how C works in additional depth and thus the advantage plays into creating better C code. However, learning them at the same time leads one to try to tie both languages closely together and results in not understanding either one completely. You would be better to pick a direction; top-down(C++ -> C -> ASM) or bottom-up(ASM -> C -> C++). Whilst I personally advocate the bottom-up approach, it seems that your current path and experience would indicate it best to use a top-down approach instead.
As for how long it'll take; everyone is different. I know someone who learned C in as little as a week or two. I know someone else who learned it in 48 hours. I've known several others who took a year or more. I myself learned the essentials of C in about a month and then added to that understanding for years afterward. It was probably a decade before I noticed that I'd stopped seeing anything new. Everyone is a little different. Trying to measure it will only slow you down; just learn.
3 months to learn basic syntax, 2 more months to learn OOP(you could skip this cause C isnt OOP) and the Standard Template Library. after that transferring to C would take about 2-4 weeks although i really think you should stick with C++. I personally dont know long it will take to learn the low level stuff. i think learning ASM would be a living hell but once you do, i think you would make a really badass cracker :D
I'm going to disregard indicated times since any accuracy would be entirely coincidental and should not be perceived as anything more.
Classroom environments tend to alter learning speed drastically; be it for better or worse. Object-orientation is possible in C. Saying "C isn't OOP" is simply incorrect, but few seem to understand that. Unfortunately, few classes teach STL adequately.
ASM really isn't a "living hell". As with most things, the syntax itself is finite and in the case of ASM, it's even more true. Once you understand the basic syntax and structure, every else is just reference/memorization. There are thousands of potential instructions that could be used in ASM. Many are common among different processors and even architectures. Many others are specific to just even a single model of a specific line of processors. You needn't memorize all of it. Just learn the basic syntax and find some good reference material.
The important thing to remember when writing in ASM is to PLAN your code. Plan it out, draw a flowchart, write a process flow, figure out how it's meant to work. Then step through each part of the plan and carefully determine what method you would prefer to use to accomplish that section. When you figure out the method, you use your reference material to find what would best be used to follow it. Then it's just a matter of repeating the process as necessary and putting the pieces together. The language itself is not difficult. The discipline involved in becoming good at it is a different matter.
I suppose so. I mean, it's not like I wasn't planning on learning C++ at some point, I just wanted to do C first because I hear it's a better idea. Oh well, I guess there's nothing I can do. I guess I could learn C++ through all the classes I'm going to take and then when I'm done I can switch to C and ASM.
Cool.
Whilst it is best to learn C prior to C++, what matters is that you're learning. As previously mentioned, many people have gone from C++ to C and turned out fine. Many others have gone from C++ to Java to C# to Objective-C and then, somehow, to C. Some people never learn C. Walking the correct path is more important than choosing the correct entrance.
Again, don't do C and ASM together.
-
Explain why C should be faster than C++. That doesn't make any sense to me, because you already said:
C is faster because in C++ the compiler has to account for OOP and other stuff and so on average C++ code will run slower. As a general rule, the higher level you get in programming languages, the slower it will be. Assembly is faster than C, C is faster than C++ and Obj-C, C++ and Obj-C are faster than Java, Java is faster than python, php, etc. It isn't the libraries it is how the compiler can optimize one's code. There are certain things it can do in C faster and better because it doesn't have to take into account things found in C++.
@OP I learned Java and then C++ and then C. It doesn't matter the order *that* much but a lot of what you learn in C can be applied to C++ (except for some things involving void* casting and a few other minor things which you don't deal with often in most cases). I would say, if your class is in C++ just learn C++ as pretty much everything (even OOP!) can be applied to C.
When I say OOP can be applied to C, I am right, it's just a little messier. In C++ for instance, try substituting "class" for "struct" and in most cases your code will compile and function the same. C has structs and they function very similarly although there are more restrictions. It isn't right to say that you can't do OOP in C, it's just a little more complicated for some things.
-
C is faster because in C++ the compiler has to account for OOP and other stuff and so on average C++ code will run slower. As a general rule, the higher level you get in programming languages, the slower it will be. Assembly is faster than C, C is faster than C++ and Obj-C, C++ and Obj-C are faster than Java, Java is faster than python, php, etc. It isn't the libraries it is how the compiler can optimize one's code. There are certain things it can do in C faster and better because it doesn't have to take into account things found in C++.
Uhh...no? You should know better than that. Rephrasing is the very least of what needs to happen here. The sheer level of interdependent structures involved with a system supporting all the complexity of every language means that it's impossible to correctly make such a statement.
Python is, in many(, many, many, many, many, many, many, ...) cases, faster than Java. The C compilation process involves preprocessing, translating, assembling and linking. The 'translation' part is important since it involves, essentially, translating the written C code to equivalent ASM. Whilst it is certainly the compiler's responsibility to try to optimize this as nicely as possible, the main point is that C and ASM are effectively, for a certain period of time, the same. It is entirely possible that a compiler could generate more optimized ASM than someone could do by hand(not that they couldn't refine it given time & experience, but you get the point, I hope). As stated previously, there are instances where C++ code has performed better than equally-optimized C. The main point is that the language does not, itself, decide the performance. Rather it is the resulting code that actually runs through the processor. Java is a little different, of course, since it runs on a VM. Also, it sucks.
I can tear up this small block of text further, but later. Let's move on...
@OP I learned Java and then C++ and then C. It doesn't matter the order *that* much but a lot of what you learn in C can be applied to C++ (except for some things involving void* casting and a few other minor things which you don't deal with often in most cases). I would say, if your class is in C++ just learn C++ as pretty much everything (even OOP!) can be applied to C.
When I say OOP can be applied to C, I am right, it's just a little messier. In C++ for instance, try substituting "class" for "struct" and in most cases your code will compile and function the same. C has structs and they function very similarly although there are more restrictions. It isn't right to say that you can't do OOP in C, it's just a little more complicated for some things.
I don't really note any change with void-pointer casting in C++ from C. As well, your class-to-struct suggestion doesn't appear to emphasize your point as an example of C handling object-orientation.
-
If you don't consider the JVM startup time and code properly Java will most likely be a lot faster than Python. At least it in pretty much all task I've tried in both languages. Java as a reputation of being super slow for not reasons really. It certainly has a lot of bad stuff but speed isn't one of them.
Also for writing server applications I highly recommend a language like Go or Javascript (Node.JS and others).
-
IMO, the speed difference between c and C++ is vritually non existant.
OOP is merely a programing paradigm that is used, and while yes there are more abstractions used in using classes and objects, I think that programming style and algorithm development will affect your code optimization way the fuck more rather than if you are using a class versus a bunch of structures (c vs c++).
Using classes is really helpful for large projects that need to reuse a set of variables and certain methods to manipulate them over and over again. Its kinda like using functions, but instead you are combining functions and variables together.
WINAPI programming is mainly done in C and does not really use many things from c++, but you can always combine the two (for example you can design your own class using win32 api functions).
Once you start learning c++, you will learn c functions as well. A lot of things used in C++ are nearly identical to C. Basic things like loops, structures, variables, are identical to C and C++. Both languages use pointers (c++ includes references). The only main difference is that in c++ you have to learn how to use Classes and templates.
Not really a BIG difference there.
Even if you find yourself taking a C++ class, you will often stumble across C stuff because a lot of C functions are already there and are working, so why reinvent the wheel?
Saying that you want to learn C before C++ is like saying that you want to learn how to read before you write. Makes no sense. While you are learning to read, you are also learning how to write at the same time. In a typical C++ beginner book, the first 8 or so chapters deal with things that C and C++ share the same. The other half of the book is talking about Classes, inheritance, templates, namespaces, and C++ i/o stream. Loops, Variables, functions, and procedural programming paradigm are the things that each language shares in common (same with java, and many other languages as well.)
Makes no sense.
C++ is just C with classes. Not really a big difference.
"Also for writing server applications I highly recommend a language like Go or Javascript (Node.JS and others)."
I think you are getting confused. Javascript is a client side language, rendered and done through the browser. Server side applications are usually done in PHP.
-
IMO, the speed difference between c and C++ is vritually non existant.
OOP is merely a programing paradigm that is used, and while yes there are more abstractions used in using classes and objects, I think that programming style and algorithm development will affect your code optimization way the fuck more rather than if you are using a class versus a bunch of structures (c vs c++).
Using classes is really helpful for large projects that need to reuse a set of variables and certain methods to manipulate them over and over again. Its kinda like using functions, but instead you are combining functions and variables together.
WINAPI programming is mainly done in C and does not really use many things from c++, but you can always combine the two (for example you can design your own class using win32 api functions).
Once you start learning c++, you will learn c functions as well. A lot of things used in C++ are nearly identical to C. Basic things like loops, structures, variables, are identical to C and C++. Both languages use pointers (c++ includes references). The only main difference is that in c++ you have to learn how to use Classes and templates.
Not really a BIG difference there.
Even if you find yourself taking a C++ class, you will often stumble across C stuff because a lot of C functions are already there and are working, so why reinvent the wheel?
Saying that you want to learn C before C++ is like saying that you want to learn how to read before you write. Makes no sense. While you are learning to read, you are also learning how to write at the same time. In a typical C++ beginner book, the first 8 or so chapters deal with things that C and C++ share the same. The other half of the book is talking about Classes, inheritance, templates, namespaces, and C++ i/o stream. Loops, Variables, functions, and procedural programming paradigm are the things that each language shares in common (same with java, and many other languages as well.)
Makes no sense.
C++ is just C with classes. Not really a big difference.
"Also for writing server applications I highly recommend a language like Go or Javascript (Node.JS and others)."
I think you are getting confused. Javascript is a client side language, rendered and done through the browser. Server side applications are usually done in PHP.
Umm...node.js is built specifically for server stuff. It's server side. It's not really like traditional JS, even though its the same language afaik.
Also, i wouldn't really agree with c++ being just c with OOP. Yeah, it has some similar stuff, but many languages are similar to c. Im not very familiar with the c's yet, but from what ive heard there are important differences beyond that, which is why people even take the time to learn both.
(http://www.hongkiat.com/blog/node-js-server-side-javascript/ First sentence.)
-
C++ is absolutely far more than "C with classes" or "C with OOP". First, OOP is more technique. As previously stated; a design paradigm. C++ is not actually an OOPL. It does, however, have features which help support object-oriented design. Some of these features, which are contained within C++ and not C, include: streams, operator overloading, function overloading, templates, improved scope control(private, public, etc.), virtual functions, inheritance, etc. There is, indeed, a HUGE difference between C & C++. In learning 1 language, you learn part of the syntax of the other. Fortunate for those who begin with C, you are more proficient in C++ with a knowledge of C than you would be in C with knowledge of C++. Example: if you know how to use a map<char*, char*> in C++, you would have a difficult time reproducing such a thing in C whilst just learning. Conversely, if you know how to C, a hashtable isn't a horrible thing to conceive and in learning C++, a map is just an added tool for your arsenal.
-
I think you are getting confused. Javascript is a client side language, rendered and done through the browser. Server side applications are usually done in PHP.
No.. NodeJS (http://nodejs.org/) is made for server-side applications in Javascript. So is Backbone.JS (http://backbonejs.org/), SpiderMonkey and some others. A lot of websites and web applications are moving away from PHP for these languages and other frameworks like Ruby on Rails, Django, etc.
-
If I am to understand this... Do you see C++ as taking a 'skid' approach? Perhaps because certain things may be easier in C++ than C? If this is so, please don't confuse 'difficult' with 'better'. Using Gentoo doesn't make one a more 'hardcore' Linux user(only, hopefully, a more patient one). Just because something is easier doesn't mean that it's a shortcut or excuse or some cheap way out.
Not at all. I was saying that I want to stick with PHP/MySQL so I can gain a better understanding of websites and SQL injecting. The skid approach I was refering to is in just taking common SQL injections and attempting them on every website I come across, instead of gaining an actual understanding of the languages involved. I wasn't saying that learning C++ is a skid approach at all.
I was really hoping to take more of this approach: C -> ASM and then C++ at some other point in life. I would take the ASM -> C -> C++ approach because that sounds like a lot of fun, but if I 'm going to be taking C++ classes it seems to make sense to make the most out of those classes and really learn C++ and then later move on to C -> ASM.
That's just not really what I wanted to do though. If I weren't taking these classes I would go for C then ASM, or ASM -> C. I have never heard anyone recommend it that way until you Xires. That way sounds fun.
-
Not at all. I was saying that I want to stick with PHP/MySQL so I can gain a better understanding of websites and SQL injecting. The skid approach I was refering to is in just taking common SQL injections and attempting them on every website I come across, instead of gaining an actual understanding of the languages involved. I wasn't saying that learning C++ is a skid approach at all.
I was really hoping to take more of this approach: C -> ASM and then C++ at some other point in life. I would take the ASM -> C -> C++ approach because that sounds like a lot of fun, but if I 'm going to be taking C++ classes it seems to make sense to make the most out of those classes and really learn C++ and then later move on to C -> ASM.
That's just not really what I wanted to do though. If I weren't taking these classes I would go for C then ASM, or ASM -> C. I have never heard anyone recommend it that way until you Xires. That way sounds fun.
PHP is a good gateway to drugs :). Better than python and whatnot, (personal reasoning). When you get involved into PHP you will be almost forced to OOP practices in modern frameworks. Who will open a gate into the world of OOP C++ :) goodluck :D
-
C is faster because in C++ the compiler has to account for OOP and other stuff and so on average C++ code will run slower. As a general rule, the higher level you get in programming languages, the slower it will be. Assembly is faster than C, C is faster than C++ and Obj-C, C++ and Obj-C are faster than Java, Java is faster than python, php, etc. It isn't the libraries it is how the compiler can optimize one's code. There are certain things it can do in C faster and better because it doesn't have to take into account things found in C++.
I quoted supermario, who said you can use most C code just like that in C++.
And my question was build upon that statement. If you can use C code in C++ why would the same code be slower compiled as C++ code than compiled as C code?
Your answer is based on the usage of OOP and other features C doesn't have. But that was not my question. The reason is, that if lucid wants to write fast running programs and has to learn C++, he can as well just NOT use OOP and other features that may result in a worse performance to write his speed critical code and still wouldn't have a disadvantage.
Also: It is much too simple to say that code on a higher abstraction level will result into a slowlier running program; or that more optimization leads to faster machine code. There are too many factors not taken into account.
I don't think this discussion belongs to lucids thread, though.
Edit:
Java as a reputation of being super slow for not reasons really. It certainly has a lot of bad stuff but speed isn't one of them.
The reason is that Java was indeed slow before they introduced just-in-time compilation. Some people stated that on the internet while it was still a valid complaint and every noob who wants to find some arguments against Java just rephrases these statements until now.
-
C++ is like a superset of C . And for sockets programming C is better , but hey ? C++ is C too ! The winsocks was made for C . C++ is better , C is considered by most as closer to hardware than C++ ( I don't know why though). C++ is C with additional features like OOP , and OOP should be preferred over procedural for neater , lesser and sleeker code . Overall I would rate C++ 10/10 while C 8/10 (no offense) . Additional features do matter . You can learn either C or C++ and then learn the other one because it is not really different .(Also you get to learn C# at the same time , which is like the easiest version of C++-thats right , we don't have pointers in C#)
I've learned C++ myself(self learned) and I never found a reason for downgrading to C . For the sockets programming it is not really different because C++ ==Superset.Of.C.
-
C++ is like a superset of C . And for sockets programming C is better , but hey ? C++ is C too ! The winsocks was made for C . C++ is better , C is considered by most as closer to hardware than C++ ( I don't know why though). C++ is C with additional features like OOP , and OOP should be preferred over procedural for neater , lesser and sleeker code . Overall I would rate C++ 10/10 while C 8/10 (no offense) . Additional features do matter . You can learn either C or C++ and then learn the other one because it is not really different .(Also you get to learn C# at the same time , which is like the easiest version of C++-thats right , we don't have pointers in C#)
I've learned C++ myself(self learned) and I never found a reason for downgrading to C . For the sockets programming it is not really different because C++ ==Superset.Of.C.
Wow...I can't believe i just read that.
-
Wow...I can't believe i just read that.
Exactly! .... xD It was extremely stupid but a little funny at the same time.
-
As for the 'closer to the hardware' issue here is a link:
http://electronics.stackexchange.com/questions/3027/is-c-suitable-for-embedded-systems
It mostly boils down to dynamic memory and abstraction from hardware. C++ tries to get you away from the hardware, which is why it was kinda made in the first place.
Classes, inheritance, dynamic memory management, etc.. are pushed by C++ to make coding simpler. This is strictly for software developers. Embedded system developers and people working with bare metal not so much. Sure you can go ASM but that is CPU specific, but C is not. C lets the compiler handle it. C is closest you get to universal before ASM, minus all the crappy that's going to Bork your project. This topic can go way off coarse quickly with both sides of the argument. Just making things a bit more clear.
Compile firmware for an 8bit AVR in C then in C++ and see where ya get quicker.
-
Exactly! .... xD It was extremely stupid but a little funny at the same time.
Why ? All I said was what I've learned .Can you let me know which part of this is stupid ?(I will correct myself , sorry)
-
Why ? All I said was what I've learned .Can you let me know which part of this is stupid ?(I will correct myself , sorry)
Well, first of all, it's a jumbled up mess of a post. Then you go on to mention 'winsocks was made for C ." mind explaining this?
"Overall I would rate C++ 10/10 while C 8/10 (no offense)" lulwut?
"Also you get to learn C# at the same time , which is like the easiest version of C++-thats right , we don't have pointers in C#" This is just stupid. What? Can't you understand pointers?
And the whole post is just stupid. If you're going to say one language is better than another then please, write a clear and coherent post, and detail your reasons.
-
Well, first of all, it's a jumbled up mess of a post. Then you go on to mention 'winsocks was made for C ." mind explaining this?
"Overall I would rate C++ 10/10 while C 8/10 (no offense)" lulwut?
"Also you get to learn C# at the same time , which is like the easiest version of C++-thats right , we don't have pointers in C#" This is just stupid. What? Can't you understand pointers?
And the whole post is just stupid. If you're going to say one language is better than another then please, write a clear and coherent post, and detail your reasons.
It's just his explaination. Everyone has their own. Back on topic.
-
Well, first of all, it's a jumbled up mess of a post. Then you go on to mention 'winsocks was made for C ." mind explaining this?
"Overall I would rate C++ 10/10 while C 8/10 (no offense)" lulwut?
"Also you get to learn C# at the same time , which is like the easiest version of C++-thats right , we don't have pointers in C#" This is just stupid. What? Can't you understand pointers?
And the whole post is just stupid. If you're going to say one language is better than another then please, write a clear and coherent post, and detail your reasons.
I am not saying one is better than other . I said OOP approach was better than procedural and that is what makes c++ 'more' useful because it lets you have neater and sleeker code . Also for winsocks , isn't the sockets library of windows winsocks.h or winsockets.h was for C coders and that c++ coder might have to learn a little different syntax for that ?
And I never said C# is better either , all I said is that it is quiet easier than C++ and C . It has no pointers which saves you a lot of hustle , plus it was made for microsoft windows and windows GUI programming is pretty easy with it (than c++ and C) . I haven't used C# myself but my c# coder friend says it has that form elements which windows use as widgets and layouts built in and you don't really need a 3rd party GUI library to code windows programs with it (note here I am saying you don't need a 3rd party library not that you 'can't') . Also I am not saying I don't understand pointers , Being a c++ coder I do .
Again ,I am a newbie and willing to correct myself if you(or anybody) corrects me here rather than telling me how stupid I am :)
-
I am not saying one is better than other . I said OOP approach was better than procedural and that is what makes c++ 'more' useful because it lets you have neater and sleeker code . Also for winsocks , isn't the sockets library of windows winsocks.h or winsockets.h was for C coders and that c++ coder might have to learn a little different syntax for that ?
And I never said C# is better either , all I said is that it is quiet easier than C++ and C . It has no pointers which saves you a lot of hustle , plus it was made for microsoft windows and windows GUI programming is pretty easy with it (than c++ and C) . I haven't used C# myself but my c# coder friend says it has that form elements which windows use as widgets and layouts built in and you don't really need a 3rd party GUI library to code windows programs with it (note here I am saying you don't need a 3rd party library not that you 'can't') . Also I am not saying I don't understand pointers , Being a c++ coder I do .
Again ,I am a newbie and willing to correct myself if you(or anybody) corrects me here rather than telling me how stupid I am :)
That's C#.net, there is also c++.net VC++
-
That's C#.net, there is also c++.net VC++
Alright , I am going to google that . Sorry for the misconception .
-
A server, including a SOCKS server, could be created in either language. Technically C++ would make certain things potentially much easier, depending on the service for which you're coding. Please keep in mind that sockets are still typically C-based and whilst there do exist pure-C++ impelementations, they're rarely used and almost never taught/permitted in classes.
Whilst I believe it best to learn C before C++, thousands of people have taken alternate routes and turned out just fine. Some elements may be a little more difficult to wrap your head around during the first iteration or two but it certainly doesn't make it impossible or even a 'bad' thing to learn C++ first.
I strongly recommend that you take the time to fully understand what it is that you're doing. When learning C++, take some extra time to learn a few of the details(though, no need to overload yourself) so that you can get a grasp of how and why it works. What you should be after, ultimately, is knowing the language well enough to predict how the computer will react to the statements that you input BEFORE actually asking the computer to do it(e.g. before compilation).
Woah. Let me stop you right there for a second. Perhaps this was not the intention, but the term 'supercede' indicates the obsoletion of something. In this case, the statement denotes that with the invention of C++, C is obsolete. I assure you, such is most certainly NOT the case.
Perhaps, instead, you mean that C++ is a 'superset' of C. In a way, this is far more correct. Essentially, you take the C language and add a bunch of features to it to create additional language elements, syntax, constructs, etc. that provide a better 'fit' for certain applications(meaning 'uses', not 'programs'). This term fits C++ very well though it is not quite enough. C++ is indeed an independent language in its own right. This is evident in some ways with the addition of function overloading, the creation of vtables to support such a feature, and the resultant generated object code.
A C++ compiler can usually compile C code. The advantage is in the use of the C++ compiler, not in the language(not with this statement, anyway). If I were to create an interpreter that could interpret both Perl and Python code, it may be an advantage for my program..but not for 1 language or the other.
C is not low-level. I admit that people these days do 'see' it as low-level, but it isn't. As for its speed; it really depends on what you're doing with the code. There are several instances where C++ actually performs faster than equally-optimized C. GCC 4.8 marks a full switch to C++ from C(meaning the compiler itself is now coded in C++) and benefits from a few performance enhancements as a result. Intel's C & C++ compiler have been C++-based for years and, whilst its own compilation speed may not be that fantastic by comparison, can produce very heavily optimized executables. C++ allows these compilers to use additional features in different ways to analyze code and apply optimizations in manners more difficult to do in C. Of course, this is not to say that it couldn't be done in C; only that, with the additional features, it is easier in C++.
If I am to understand this... Do you see C++ as taking a 'skid' approach? Perhaps because certain things may be easier in C++ than C? If this is so, please don't confuse 'difficult' with 'better'. Using Gentoo doesn't make one a more 'hardcore' Linux user(only, hopefully, a more patient one). Just because something is easier doesn't mean that it's a shortcut or excuse or some cheap way out.
Indeed; everything you learn has a value. Deque, you are fast becoming one of my favourite members.
C is not necessarily more for drivers. C may be used more often for drivers than C++ but that is not necessarily because the language is better suited for the task. Of all the different operating systems that exist in the world, the vast majority of them are C-based. Some of this is because the code base existed prior to the popularization of C++. With C-based operating systems usually comes C-coded kernels and system libraries supporting a minimum C 'standard'(even if it's not fully 'standards-compliant'). This means that you are more likely to have an easier time coding something in C than in C++ as services for C++ may not be available within the lower levels of the OS code. Of course, once you create your own 'essential' OS component in C, you more or less force others that use it to also code in C. Thus, such a trend becomes de facto.
As for C++ being "for games". I think you can understand the error in the statement. Again, the language may more often be used for such a thing but that doesn't mean that there's any limitation either with the game field nor with the languages used. C++ has enjoyed much success in many areas, including servers. For example, InspIRCd is quickly becoming one of the most popular IRCd's available and it is written, to its core, in C++. There are webservers, mailservers, authentication systems, etc. that are all coded in C++. Whilst the C-based ones may be more popular and more common, it is not either language's fault.
I don't advise learning ASM along side C. ASM isn't really that 'difficult', per se, but it is certainly different. ASM will introduce quickly concepts that are likely to confuse someone who is just beginning in C. If you are already well familiar with ASM, it poses an advantage to learning certain parts of C. If you're already well familiar with C, learning ASM is merely understanding how C works in additional depth and thus the advantage plays into creating better C code. However, learning them at the same time leads one to try to tie both languages closely together and results in not understanding either one completely. You would be better to pick a direction; top-down(C++ -> C -> ASM) or bottom-up(ASM -> C -> C++). Whilst I personally advocate the bottom-up approach, it seems that your current path and experience would indicate it best to use a top-down approach instead.
As for how long it'll take; everyone is different. I know someone who learned C in as little as a week or two. I know someone else who learned it in 48 hours. I've known several others who took a year or more. I myself learned the essentials of C in about a month and then added to that understanding for years afterward. It was probably a decade before I noticed that I'd stopped seeing anything new. Everyone is a little different. Trying to measure it will only slow you down; just learn.
I'm going to disregard indicated times since any accuracy would be entirely coincidental and should not be perceived as anything more.
Classroom environments tend to alter learning speed drastically; be it for better or worse. Object-orientation is possible in C. Saying "C isn't OOP" is simply incorrect, but few seem to understand that. Unfortunately, few classes teach STL adequately.
ASM really isn't a "living hell". As with most things, the syntax itself is finite and in the case of ASM, it's even more true. Once you understand the basic syntax and structure, every else is just reference/memorization. There are thousands of potential instructions that could be used in ASM. Many are common among different processors and even architectures. Many others are specific to just even a single model of a specific line of processors. You needn't memorize all of it. Just learn the basic syntax and find some good reference material.
The important thing to remember when writing in ASM is to PLAN your code. Plan it out, draw a flowchart, write a process flow, figure out how it's meant to work. Then step through each part of the plan and carefully determine what method you would prefer to use to accomplish that section. When you figure out the method, you use your reference material to find what would best be used to follow it. Then it's just a matter of repeating the process as necessary and putting the pieces together. The language itself is not difficult. The discipline involved in becoming good at it is a different matter.
Whilst it is best to learn C prior to C++, what matters is that you're learning. As previously mentioned, many people have gone from C++ to C and turned out fine. Many others have gone from C++ to Java to C# to Objective-C and then, somehow, to C. Some people never learn C. Walking the correct path is more important than choosing the correct entrance.
Again, don't do C and ASM together.
First of all, thanks for taking the time to write that long and informative post. There's quite a bit of info in there.
Second, and I know this thread isn't about me keeping everyone updated about my life, but I realized I won't have enough money to take the programming classes. Which, actually excites me because I think I'm going to take Xires' recommendation of the bottom up approach. (ASM->C->C++). I've never heard anyone advocate it that way and the mere thought of learning ASM sooner than later literally makes me feel like a horny schoolgirl.
So thanks Xires for that input as well.
-
Damn, i thought i was going to have a rivel here. Im learning c++ and thats just what i wanted, good luck lucid. I guis ill have to compeet with someone els :p.
-
Uhh...no? You should know better than that. Rephrasing is the very least of what needs to happen here. The sheer level of interdependent structures involved with a system supporting all the complexity of every language means that it's impossible to correctly make such a statement.
...
I don't really note any change with void-pointer casting in C++ from C. As well, your class-to-struct suggestion doesn't appear to emphasize your point as an example of C handling object-orientation.
So I made a simplification, however, if you start using C++ features such as OOP and advanced OOP then my statement is correct. You could the the equivalent in C but it's just messy. Now this is still a bit generalized and not always true so I shouldn't have generalized that much and it's a bit misleading but meh... And well try doing:
void* test = 1;
int* test2 = (int*)test; // This will not compile
int* test3 = static_cast<int*>(test); // Probably will compile.
Just one little nit pick, not really worth a mention in retrospect.
-
So I made a simplification, however, if you start using C++ features such as OOP and advanced OOP then my statement is correct. You could the the equivalent in C but it's just messy. Now this is still a bit generalized and not always true so I shouldn't have generalized that much and it's a bit misleading but meh... And well try doing:
void* test = 1;
int* test2 = (int*)test; // This will not compile
int* test3 = static_cast<int*>(test); // Probably will compile.
Just one little nit pick, not really worth a mention in retrospect.
I apologize for not being able to explain in appropriate detail. I had a seizure a couple hours ago and am still in recovery. I did at least want to respond since I don't want others getting confused when they come across it.
void* isn't used that way.
#include <iostream>
int main(void) {
void *t1 = 1;
int *t2 = (int*) t1;
std::cout << *t1 << " : " << *t2 << std::endl;
return 0;
}
$ g++ -Wall -Wextra -W -ansi -pedantic -o cast_test{,.cpp}
cast_test.cpp: In function 'int main()':
cast_test.cpp:4:13: error: invalid conversion from 'int' to 'void*' [-fpermissive]
cast_test.cpp:7:16: error: 'void*' is not a pointer-to-object type
The error obviously points to the improper void* use. Better usage below.
#include <iostream>
int main(void) {
int t0 = 100;
void *t1 = &t0;
int *t2 = (int*) t1;
std::cout << *((int*) t1) << " : " << *t2 << std::endl;
return 0;
}
This casting is the same between both C and in C++. There is no difference just because STL gives us static_cast, dynamic_cast, const_cast, etc. C++ just gives more options, per usual.
Traditional use below.
#include <iostream>
void* func(void);
int main(void) {
int *t1;
t1 = (int*) func();
std::cout << *t1 << std::endl;
return *t1;
}
void* func(void) {
static int test = 125;
return &test;
}
C++ will do classic void* casting just like C. There is no change, you just didn't do it right.
--
Now that I have a little more clarity, I'd like it to be known that I have the utmost respect for bluechill so comments like "you schooled him even after a seizure" are not welcome. bluechill is a trusted and competent member of our staff and should be respected as such. Not everyone can know everything and I myself have consulted bluechill for assistance more than once.
-
I apologize for not being able to explain in appropriate detail. I had a seizure a couple hours ago and am still in recovery. I did at least want to respond since I don't want others getting confused when they come across it.
void* isn't used that way.
#include <iostream>
int main(void) {
void *t1 = 1;
int *t2 = (int*) t1;
std::cout << *t1 << " : " << *t2 << std::endl;
return 0;
}
$ g++ -Wall -Wextra -W -ansi -pedantic -o cast_test{,.cpp}
cast_test.cpp: In function 'int main()':
cast_test.cpp:4:13: error: invalid conversion from 'int' to 'void*' [-fpermissive]
cast_test.cpp:7:16: error: 'void*' is not a pointer-to-object type
The error obviously points to the improper void* use. Better usage below.
#include <iostream>
int main(void) {
int t0 = 100;
void *t1 = &t0;
int *t2 = (int*) t1;
std::cout << *((int*) t1) << " : " << *t2 << std::endl;
return 0;
}
This casting is the same between both C and in C++. There is no difference just because STL gives us static_cast, dynamic_cast, const_cast, etc. C++ just gives more options, per usual.
Traditional use below.
#include <iostream>
void* func(void);
int main(void) {
int *t1;
t1 = (int*) func();
std::cout << *t1 << std::endl;
return *t1;
}
void* func(void) {
static int test = 125;
return &test;
}
C++ will do classic void* casting just like C. There is no change, you just didn't do it right.
--
Now that I have a little more clarity, I'd like it to be known that I have the utmost respect for bluechill so comments like "you schooled him even after a seizure" are not welcome. bluechill is a trusted and competent member of our staff and should be respected as such. Not everyone can know everything and I myself have consulted bluechill for assistance more than once.
On Unix yes however on Windows (and this is what I was remembering) I ran into issues with using void* for threading and casting from them (generic argument passed) to a class pointer. Apparently VS complains but I just tried some stuff in clang++ and g++ and it all works as you say. So.... we're both right? Although really VS shouldn't complain but it did (at least in 2010 sp1).