|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On February 08 2015 21:29 Cynry wrote: Your main function returns an int, so you got to return an int to end it. What you return (so long as it is an int) and what it means is up to you, although I guess there are some convention. For me, -1 is an error occured, 0 nothing was done, 1 is all good.
Don't your compiler tells you about using if (x1 = x2) ? Fairly sure mine does (gcc with flags -Werror etc to show all errors). if ((x1 = x2)) would work, not with a single pair of parenthesis.
if((x1=x2)) didn't work either, I really need "==", I don't know why.
@Blisse, I'm doing this entirely for fun. I'm just messing around with programming to understand the concepts, maybe write a few programs for fun. Industrial engineering has nothing to do with coding at all, just wanted to answer ropid. Would you recommend learning C over C++ at first, or should I just stick to messing around with C++ right now? I think I'll just stick to C++ until I understand enough about coding to figure out why C might be interesting.
From the little I understand (because a lot of what I've been reading is gibberish to me :p), it seems that C++ is more or less a lot like C, it's just that some of the extra steps that you'd have to do in C (e.g. allocating variables to memory) are done for you in C++. I've already found out that an un-initialized variable in C++ can lead to explosive results.
So return 0 (or any number afaik) signifies that int main() ran successfully. Where do you check? in the console?
|
On February 08 2015 21:03 Incognoto wrote: The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine). The whole "no bullshit" thing is bullshit, though. I started with C++ and went really deep on the details of the language. There's not a whole lot of magic going on in C++, maybe save for multiple inheritance. Templates can be very complex, but at the end of the day they are only replaced with regular C++ code while compiling. You can do stupid stuff like convoluted inheritance hierarchies with all kinds of stupid overrides of virtual methods and what not, but you can do the same stuff in C, it just looks different. C also is full of abstractions.
Now I'm coding in C# and I'm perfectly fine because I just plain don't need to know how everything translates into machine code. The only thing I miss from time to time is templates, because generics just are nowhere near as powerful as templates, so you have to use reflection here and there instead. So what I am missing is more powerful means of abstraction, not closeness to machine code.
The idea that you need to know how programs work at machine level to be a great programmer is just nonsense. Assembly isn't the lowest you can go, machine code isn't the lowest either. You could try to learn the microcode that is run on your CPU, you could learn how that translates into signals and what not. None of that will make you a better programmer by itself. What you really need to understand is how abstractions work in programming. But ultimately you always rely on some abstractions to do what they promise to do.
I personally don't recommend C++ to start with, as it's a language with many pitfalls for the newbie, and I know from experience that there is plenty of awful resources out there on the internet that will teach you just the worst ways of using C++. But in general one language is as good of a starting point as another as long as you learn it properly.
|
On February 08 2015 21:53 Incognoto wrote:Show nested quote +On February 08 2015 21:29 Cynry wrote: Your main function returns an int, so you got to return an int to end it. What you return (so long as it is an int) and what it means is up to you, although I guess there are some convention. For me, -1 is an error occured, 0 nothing was done, 1 is all good.
Don't your compiler tells you about using if (x1 = x2) ? Fairly sure mine does (gcc with flags -Werror etc to show all errors). if ((x1 = x2)) would work, not with a single pair of parenthesis. if((x1=x2)) didn't work either, I really need "==", I don't know why. @Blisse, I'm doing this entirely for fun. I'm just messing around with programming to understand the concepts, maybe write a few programs for fun. Industrial engineering has nothing to do with coding at all, just wanted to answer ropid. Would you recommend learning C over C++ at first, or should I just stick to messing around with C++ right now? I think I'll just stick to C++ until I understand enough about coding to figure out why C might be interesting. From the little I understand (because a lot of what I've been reading is gibberish to me :p), it seems that C++ is more or less a lot like C, it's just that some of the extra steps that you'd have to do in C (e.g. allocating variables to memory) are done for you in C++. I've already found out that an un-initialized variable in C++ can lead to explosive results. So return 0 (or any number afaik) signifies that int main() ran successfully. Where do you check? in the console?
= parses into assignment, meaning x1=x2 means set x1 to the value of x2 (i'm skipping the details). in C/C++, everything returns a value whether you like it or not, x1=x2 returns x1, which isn't 0, which is cast to true, so the if statement is entered. == parses into equality, meaning x1==x2 returns a boolean true/false, is the value of x1 equal to x2, which is what you want.
for fun i would totally prefer a higher level language (like visual c# or java) because c/c++ doesn't allow you to do really fun stuff unless you want to learn a whole bunch of extensions and processes which take away from the "fun" of coding. but c/c++ are definitely where you should start if you want to learn.
yes, you can check in the console whether it returned error. try returning 1 and seeing what you get as a result. i believe it should say "returned with status code...." or something like that but i might be mixing up things.
|
On February 08 2015 21:58 spinesheath wrote:Show nested quote +On February 08 2015 21:03 Incognoto wrote: The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine). The whole "no bullshit" thing is bullshit, though. I started with C++ and went really deep on the details of the language. There's not a whole lot of magic going on in C++, maybe save for multiple inheritance. Templates can be very complex, but at the end of the day they are only replaced with regular C++ code while compiling. You can do stupid stuff like convoluted inheritance hierarchies with all kinds of stupid overrides of virtual methods and what not, but you can do the same stuff in C, it just looks different. C also is full of abstractions. I think the reason why C in my opinion is a "no bullshit" langauge is because of 2 things.
1. It shows you all the pitfalls you should realisticly expect when abstractation fails.
2.It shows you how to the same shit on a lower level, which is more time consuming but more mutatable at the same time.
|
On February 08 2015 20:59 Cynry wrote:Show nested quote +On February 08 2015 20:27 Dumbledore wrote: In OP there is a quote comparing programming languages depending on how close they are to the machine. It says: " Machine Lang Assembly C C++/Java/C# ..." This is utterly missleading and incorrect. C++ is a superset of C, it is compiled directly to native code (unless you do some gross CLR, which you can in C aswell). It is no further from the machine than C is. You can use every single C feature in it. C# and Java are highly abstract languages. They dont compile to native code. The applications run in what is called a "virtual machine" (no not the vmware kind), actively translating instructions and such. You lose a lot of capabilities using those languages such as being able to communicate directly to hardware. Comparing C++ to those 2 is missleading, wrong and insulting to any serious C++ programmer. The list should say "C/C++". Please fix OP. Uneducated question : As much as I agree with how you part C++ from Java and C#, are C and C++ really on the same "level" ? I was under the impression that one could write a C++ program without knowing what's going on with memory for exemple, whereas you can't really do that in C (I think). So it'd still be a level of abstraction higher. Wrong ? Whaaat ? :D
Level in this context means the relation to the machine, and C and C++ has the same. Which is why I felt annoyed that this thread is tricking people that C is closer to it. (A few posts up a guy is saying he will drop C++ for C cos its "closer").
In C++ memory management is just as crucial as in C. In C++11 Smart pointers were introduced, aka unique_ptr and shared_ptr, these allow for some kind of "automatic" memory management and should "always" be used. This will help your application use RAII (Resource Acqusition Is Initialisation). There are some differences between how you should manage memory in C and C++. In C for allocating and deallocating you should use malloc and free allover the place. In C++ malloc is now considered bad practise. You want to use "new", "delete" and smart pointers.
C++ offers smart pointers as a bonus, its not forced use. But yeah the level of c c++ is the same 
|
@incognoto:
What you can do right now is look at the debugger that's built into Visual Studio (if everything's there in the free version). You can make it go line by line through your tiny test program. You can look at what's happening to all variables. There's a "stack" where that stuff is saved on. Try creating a new function out of your "finding the determinant" line and you might intuitively understand how that works with the stack, variables and return values. You can take a look at the assembler code that your functions translated into. That might be interesting. You can probably guess what's going on if it's about integers (I don't know how floating point code looks like in assembler and I worry you shouldn't look at that, should instead do stuff with integers).
If you google "kernighan ritchie the c programming language", you'll find a pdf of the book from the C inventors. The way it's written, it doesn't talk about anything irrelevant really, just describes everything. For pointers and how dynamic memory allocation works, there's good explanations with sketches and stuff (but I don't think it has the same for the local stuff on the stack).
When you write "a = b" in something like C, that translates into "read something from memory address b and then store that into memory address a". That's why "==" is something different. When you write "a == b", that translates into "read something from memory address a and then compare that to what's at memory address b".
All of this is "imperative". There are programming languages that work differently. There are languages where when you write "a = b", you just declare to the compiler that wherever you use b, it's the same as a. The line itself does not translate into any instructions for the machine. It instead changes how the compiler will see the rest of your program.
There's a webpage "Project Euler" here: https://projecteuler.net/problems. It's a collection of simple questions where you're supposed to calculate something. You could do some of those in C. When you do that, you're thinking in a pretty different way than what you do in those other languages and those will feel weird.
Two of those weird languages that are actually in use were developed in France. There's OCaml and there's Coq. OCaml seems somewhat normal and Coq seems to be something about logic and proofs. There might be research groups in your faculty and courses that use one of those two?
|
On February 08 2015 21:58 spinesheath wrote:Show nested quote +On February 08 2015 21:03 Incognoto wrote: The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine). The whole "no bullshit" thing is bullshit, though. I started with C++ and went really deep on the details of the language. There's not a whole lot of magic going on in C++, maybe save for multiple inheritance. Templates can be very complex, but at the end of the day they are only replaced with regular C++ code while compiling. You can do stupid stuff like convoluted inheritance hierarchies with all kinds of stupid overrides of virtual methods and what not, but you can do the same stuff in C, it just looks different. C also is full of abstractions. Now I'm coding in C# and I'm perfectly fine because I just plain don't need to know how everything translates into machine code. The only thing I miss from time to time is templates, because generics just are nowhere near as powerful as templates, so you have to use reflection here and there instead. So what I am missing is more powerful means of abstraction, not closeness to machine code. The idea that you need to know how programs work at machine level to be a great programmer is just nonsense. Assembly isn't the lowest you can go, machine code isn't the lowest either. You could try to learn the microcode that is run on your CPU, you could learn how that translates into signals and what not. None of that will make you a better programmer by itself. What you really need to understand is how abstractions work in programming. But ultimately you always rely on some abstractions to do what they promise to do. I personally don't recommend C++ to start with, as it's a language with many pitfalls for the newbie, and I know from experience that there is plenty of awful resources out there on the internet that will teach you just the worst ways of using C++. But in general one language is as good of a starting point as another as long as you learn it properly. +(++*(std::make_unique<int>(0)));
|
On February 08 2015 21:32 Blisse wrote: C++ can do everything C can.
Variable length arrays exist in c99 but not c++.
|
On February 08 2015 22:20 Blisse wrote:Show nested quote +On February 08 2015 21:53 Incognoto wrote: So return 0 (or any number afaik) signifies that int main() ran successfully. Where do you check? in the console? yes, you can check in the console whether it returned error. try returning 1 and seeing what you get as a result. i believe it should say "returned with status code...." or something like that but i might be mixing up things.
Actually if the C function returns 0 it means success, anything else means that something went wrong. You can use this to handle errors.
if (!input) { return 1; // no input specified }
if (fopen("myfile", "r") == NULL) { return 2; // could not read file, for more details see strerror(errno) if <errno.h> is included }
return 0; // all is well
|
I have this particular question in my mind: I'm building this web application which, in server side, uses nodejs to get constant stream of data from a 3rd party API and store it in my NoSQL database. I have finished developing the server side and now I'll move on with the client side. I'm wondering what I should use for the front end. I'm stuck between:
1- Front end with EmberJS and having a JSON API for database connectivity (or whatever Ember offers for that) 2- Same thing as #1, just replace EmberJS with AngularJS 3- Use Express and eliminate the need for JSON API for DB connectivity.
What are the pros and cons of each one?
|
Hyrule18982 Posts
On February 08 2015 20:27 Dumbledore wrote: In OP there is a quote comparing programming languages depending on how close they are to the machine. It says: " Machine Lang Assembly C C++/Java/C# ..." This is utterly missleading and incorrect. C++ is a superset of C, it is compiled directly to native code (unless you do some gross CLR, which you can in C aswell). It is no further from the machine than C is. You can use every single C feature in it. C# and Java are highly abstract languages. They dont compile to native code. The applications run in what is called a "virtual machine" (no not the vmware kind), actively translating instructions and such. You lose a lot of capabilities using those languages such as being able to communicate directly to hardware. Comparing C++ to those 2 is missleading, wrong and insulting to any serious C++ programmer. The list should say "C/C++". Please fix OP. I'm not changing a quote from someone else from 3 years ago because you don't like it. It's really not insulting at all unless someone decides they want to be nitpicky. It's a very basic list meant to get a point across, not a specific and universal classification of C++.
And I'm well aware of how these languages work and I'm fairly sure donut is too.
|
On February 08 2015 23:49 Rollin wrote:Variable length arrays exist in c99 but not c++.
You got me there. However you could always use dynamic arrays in C++ or std::vector. VL Arrays were taken out of the C++ Standard fot good reasons though. e.g. sizeof() wont always work at compile time, New syntax needed for multi dimensional VL Arrays that are passed as arguments. And other stack problems it can possibly introduce.
|
On February 09 2015 00:40 Djagulingu wrote: I have this particular question in my mind: I'm building this web application which, in server side, uses nodejs to get constant stream of data from a 3rd party API and store it in my NoSQL database. I have finished developing the server side and now I'll move on with the client side. I'm wondering what I should use for the front end. I'm stuck between:
1- Front end with EmberJS and having a JSON API for database connectivity (or whatever Ember offers for that) 2- Same thing as #1, just replace EmberJS with AngularJS 3- Use Express and eliminate the need for JSON API for DB connectivity.
What are the pros and cons of each one?
You could always try some full stack framework, like MEAN. It uses NoSQL (Mongo), Express, Angular and Node so you could have it all in one neat package.
|
On February 09 2015 01:37 Manit0u wrote:Show nested quote +On February 09 2015 00:40 Djagulingu wrote: I have this particular question in my mind: I'm building this web application which, in server side, uses nodejs to get constant stream of data from a 3rd party API and store it in my NoSQL database. I have finished developing the server side and now I'll move on with the client side. I'm wondering what I should use for the front end. I'm stuck between:
1- Front end with EmberJS and having a JSON API for database connectivity (or whatever Ember offers for that) 2- Same thing as #1, just replace EmberJS with AngularJS 3- Use Express and eliminate the need for JSON API for DB connectivity.
What are the pros and cons of each one? You could always try some full stack framework, like MEAN. It uses NoSQL (Mongo), Express, Angular and Node so you could have it all in one neat package. I actually want to use couchbase as the nosql database because it is lotsnlots of times faster when it comes to write operations per second and that is what my server is going to do (think of it like some guy who picks up a single paper from an endless pile of papers, stamp it and put it in another pile and thus i don't want my pile to randomly crash).
|
On February 08 2015 21:58 spinesheath wrote:Show nested quote +On February 08 2015 21:03 Incognoto wrote: The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine). The whole "no bullshit" thing is bullshit, though. I started with C++ and went really deep on the details of the language. There's not a whole lot of magic going on in C++, maybe save for multiple inheritance. Templates can be very complex, but at the end of the day they are only replaced with regular C++ code while compiling. You can do stupid stuff like convoluted inheritance hierarchies with all kinds of stupid overrides of virtual methods and what not, but you can do the same stuff in C, it just looks different. C also is full of abstractions. Now I'm coding in C# and I'm perfectly fine because I just plain don't need to know how everything translates into machine code. The only thing I miss from time to time is templates, because generics just are nowhere near as powerful as templates, so you have to use reflection here and there instead. So what I am missing is more powerful means of abstraction, not closeness to machine code. The idea that you need to know how programs work at machine level to be a great programmer is just nonsense. Assembly isn't the lowest you can go, machine code isn't the lowest either. You could try to learn the microcode that is run on your CPU, you could learn how that translates into signals and what not. None of that will make you a better programmer by itself. What you really need to understand is how abstractions work in programming. But ultimately you always rely on some abstractions to do what they promise to do. I personally don't recommend C++ to start with, as it's a language with many pitfalls for the newbie, and I know from experience that there is plenty of awful resources out there on the internet that will teach you just the worst ways of using C++. But in general one language is as good of a starting point as another as long as you learn it properly. As a rubyist I can only kiss you for this comment. C is a fine language, but it's not the holy grail of programming as so many people propagate. At the end it's always a matter of what level of abstraction is best for the kind of program you want to write. Also: While it is true, that you can do lots of run-time and memory optimizations in C, it's also true that most applications don't need to be optimized - at least not in that way.
|
On February 08 2015 21:03 Incognoto wrote:the discussion which took place on the last two pages was really interesting, thanks for that. @Ropid, I'm doing a master's degree in industrial engineering. Coding in VBA seems to have almost no link whatsoever to the rest of what we do, so I'm not really sure what the fuck we're doing. I decided to pick up C++ for fun, completely on my own. So far I've written just one program, in C++, using visual C++. It will solve a basic univariate quadratic function. It was fun to do, I did it reading the first few pages of learncpp.com and using google whenever I couldn't get something to work (disregard the weird comments I used while writing): + Show Spoiler + #include "stdafx.h" // Uncomment this line if using Visual Studio #include <iostream> int main() { //telling the user what's up std::cout << "Dear Sir, regarding your recent enquiry as to me, the Computer, helping you do" << std::endl; std::cout << "your math homework, I have decided that I shall give you all the aid which you" << std::endl; std::cout << "shall need in order to successfully solve the math problem which has "<< std::endl; std::cout << "been bestowed upon you." << std::endl; std::cout << "I believe that indeed, you were given a polynomial equation to solve." << std::endl; std::cout << std::endl;
//initializing the first variables that the user will enter float a=0; float b=0; float c=0;
//the user will enter the variables for each value, whilst being treated like a gentleman: std::cout << "Let us begin. Good Sir, please enter the first coefficient: "<< std::endl; std::cin >> a;
std::cout << "Good Sir, please enter the second coefficient: "<< std::endl; std::cin >> b;
std::cout << "Good Sir, please enter the third coefficient: "<< std::endl; std::cin >> c; std::cout << std::endl;
//finding da determinant: float d=0; d=((pow(b,2))-4*a*c);
std::cout << d << std::endl; //checking if determinant is negative: if(d<0) { std::cout << "The determinant being negative, there is no solution." << std::endl; } else { //defining solutions and doing da maths: float x1=0; float x2=0;
x1=(-b+sqrt(d))/(2*a); x2=(-b-sqrt(d))/(2*a);
//portraying the result, which depends on the value of determinant: if(x1==x2) { std::cout << "The only solution to the equation is: " << x1 << std::endl; } else { std::cout << "The first solution to your problem would be: " << x1 << std::endl; std::cout << "This is the second result: " << x2 << std::endl; } }
//ending message std::cout << std::endl; std::cout << "My regards have been sent. Press enter to cheerio."<< std::endl;
//preventing the retarded console from shutting down on its own std::cin.clear(); std::cin.ignore(255, '\n'); std::cin.get(); return 0; }
Having read the OP, I might drop C++ for now and concentrate on Assembly or C, since apparently those languages are closer to the actual machine. Learning those would make me understand programming on a more "fundamental" level. Not entirely sure. This is mostly just a hobby I'm starting, really for fun. However it seems that coding can be dangerous if self taught. For example, in my program: if(x1==x2)
Originally, I wrote " if(x1=x2) " and what the program would do is always give me two solutions which were equal. I find it somewhat alarming that the condition I set for an "if loop" would actually transform x2 instead. Using a bit of google, I found that a work if loop in another program just used "==" instead of "="; when I edited my line with that, it ended up working. I find this similar to playing with fire for some reason, like learning to code this way might have me ignoring really fundamental concepts or something. The reason I started with C++ over C or Java was that C++ seemed to be the powerful, no bullshit language. However I'm now in doubt (especially when reading the post just above mine). PS: everyone uses "return 0;" but I still don't know why the hell it's there. To return 0 to the machine so it knows that the program finished? Why would we need to do that? If the program works, it works, if it doesn't, it doesn't. The machine doesn't care, it's just there to execute codes. Or it it?
You may use this to hold console open:
system("PAUSE")
|
On February 09 2015 00:25 Manit0u wrote:Show nested quote +On February 08 2015 22:20 Blisse wrote:On February 08 2015 21:53 Incognoto wrote: So return 0 (or any number afaik) signifies that int main() ran successfully. Where do you check? in the console? yes, you can check in the console whether it returned error. try returning 1 and seeing what you get as a result. i believe it should say "returned with status code...." or something like that but i might be mixing up things. Actually if the C function returns 0 it means success, anything else means that something went wrong. You can use this to handle errors. if (!input) { return 1; // no input specified }
if (fopen("myfile", "r") == NULL) { return 2; // could not read file, for more details see strerror(errno) if <errno.h> is included }
return 0; // all is well
not sure where we were in disagreement
edit: nvm i didnt see the stuff in incognoto's parentheses
|
java question
If I pass a reference to another instance as an argument, can I make it so that all of the methods in the new instance will recognize the fields in that reference? like for example a string in the original instance, I can print it from within the constructor of the new instance, but if I try to print it from a method that is called in that constructor, it won't work unless I pass it on as a parameter to that method as well. but that seems really redundant if I am going to be using a bunch of methods... having to put the reference as a parameter over and over. does anyone understand what I am talking about?
|
It sounds like you need inheritance, but I'm not 100% sure what you're asking.
|
class1{ String mystring="blah" }
class2 { class1 x = new class1 class3 y = new class3(x)}
class3{
class3(class1 thing){ System.out.print(thing.mystring); method(); }
method(){ System.out.print(thing.mystring); }}
hopefully the code is good here. I made it as simple as possible. in this example I believe that mystring would print out as "blah" the first time, but the 2nd time method will not see thing anymore. so it won't print out mystring, it would just have an error. I am wondering if there is an easy way to make method and any other methods in class3 to see thing.
|
|
|
|