|
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 May 30 2012 03:43 gyth wrote:Show nested quote +On May 30 2012 01:26 typedef struct wrote: This debate says a lot about object-oriented programming in general. It isn't fair to indict OOP based on how C++/java tacked on their buzzword support.
I was referring to OOP in general, not any particular language. Earlier in the thread people were arguing against getters/setters because they're not OOP. In "perfect" OOP, classes expose behavior and hide state. Getters/setters break this, but are still needed for any non-trivial OOP.
|
|
Hello everyone. I am trying to write an iPad app that reads/writes to an excel document. From what I have read, there is no library that will allow me to do this, but there are a couple of alternative ways:
1) I could use the app to write to a .csv file and then open that in excel. The problem with this is that the excel file has many 'sheets', and each .csv file can only hold one sheet.
2) I could use the app to write to a Google Docs file, then somehow read that file and update the original excel file. This seems complicated though.
I know neither of these is ideal, but iPads and Windows computers are what I have to work with.
I'm just looking for what you guys think the better option is, or if you have one of your own. Thanks.
|
Speaking of heated debate topics, why is GO TO considered such a bad feature for a language to have?
I mean, I get that if you are completely careless with it, you can access memory that hasn't been allocated for your program, but it's extremely hard to screw up that bad. You almost have to force it to happen.
The thing is though, GO TO provides an effective way of exiting complex control structures. It is a gigantic pain to try to get a large group of nested for-loops to terminate early without GO TO, but with GO TO, it can be done with the addition of a single if-statement.
I was making a Turing Machine simulator for a class I was taking. The simulator was written in Java. The state of the machine ended up being stored in a 4D array, meaning it had to be accessed by a nesting of for-loops. It was such a pain to break out of those loops without GO TO.
|
I think that one reason is that if you have to resort to goto then your code isn't written very well and there is probably (not certainly) a cleaner/safer way to do so. At least that's what I've been taught.
|
Hyrule18980 Posts
On May 30 2012 07:35 PachaL wrote: Hello everyone. I am trying to write an iPad app that reads/writes to an excel document. From what I have read, there is no library that will allow me to do this, but there are a couple of alternative ways:
1) I could use the app to write to a .csv file and then open that in excel. The problem with this is that the excel file has many 'sheets', and each .csv file can only hold one sheet.
2) I could use the app to write to a Google Docs file, then somehow read that file and update the original excel file. This seems complicated though.
I know neither of these is ideal, but iPads and Windows computers are what I have to work with.
I'm just looking for what you guys think the better option is, or if you have one of your own. Thanks. You can use the XML format, which supports multiple sheets, all styling and formatting, and is compatible with Excel, OpenOffice, and GoogleDocs.
|
@PachaL Another option is to combine your app with a web backend. There are many libraries to read/write excel files on the webserver. Then you can use whatever language and libary you want. You have the extra complexity for the communication between app and sever though.
@Millitron In machine code, every if and loop are essentially GOTO's. The problem with GOTO is that it makes it easy to write complicated spaghetti-code. Then the control flow is hard to figure out. If you have 4 nested loops in one function, firstly I'd refactor that into smaller functions. The code is then easier to follow and more self-documented. Second, maybe you could use a 1D array with classes/objects instead of a 4D array. Then move some code to those classes.
|
|
On May 30 2012 07:38 Millitron wrote: Speaking of heated debate topics, why is GO TO considered such a bad feature for a language to have?
I mean, I get that if you are completely careless with it, you can access memory that hasn't been allocated for your program, but it's extremely hard to screw up that bad. You almost have to force it to happen.
The thing is though, GO TO provides an effective way of exiting complex control structures. It is a gigantic pain to try to get a large group of nested for-loops to terminate early without GO TO, but with GO TO, it can be done with the addition of a single if-statement.
I was making a Turing Machine simulator for a class I was taking. The simulator was written in Java. The state of the machine ended up being stored in a 4D array, meaning it had to be accessed by a nesting of for-loops. It was such a pain to break out of those loops without GO TO.
Work for a company that builds a C/C++ compiler. Here is my chiming in on why getters/setters is bad from a performance standpoint (thus design), and also why you should be glad GOTO has been wiped.
These practices are not mainstream, and have for the most part been purged from the global corporate and open source code base, and for a reason! It is dismal that getters/setters is being snuck back in by high school CS teachers and design by committee curriculum. (I do not mean that any getter or setter is bad design, just that ALL classes MUST have getters/setters, and ALL variables MUST be private)
Lets talk performance. Ill start with GOTO because its an easy target: Back in ye olden BASIC times, GOTO's were the go to (heh) method for program flow. This was alright, and did not typically affect speed of computations nor code size in any significant manner, because the code assembled almost directly into its literal machine code translation, with no optimizations. Then came Dennis Ritchie and C.
A compiled language will look almost nothing like itself when turned into machine code. Most notably is the inclusion of the stack and functions. Function calls replaced the LABEL A -> GOTO B -> GOTO A spaghetti by including the address of the branch to instruction onto the stack, and branching to the stack popping upon returning form a function. This is incredibly faster as a processor optimized for branch prediction would almost always have the next instruction loaded into the cache, compared to the GOTO method.
This is one of many reasons why people tell you to never use GOTO under any circumstance. It may seem efficient at the time, but in reality, it provides even more complexity where well thought out program flow would be better to begin with.
For Getters/Setters, the compiler will optimize out getters and setters 90% of the time and turn them into inline functions, which will be effectively what you wanted to put in your code anyway. the other 10% of the time, in things such as generic classes (http://en.wikipedia.org/wiki/Template_(C%2B%2B) )or getting/setting 32-bit or 64 bit structs that would like to be optimized into registers , you will feel a significant performance hit by using this sort of code design. It is not poor design to completely neglect getters and setters from code, as they definitely have their design uses for abstraction.
It is poor design to write code that needlessly complicated where a more understandable alternative exists that is also closer to what the cpu actually does. It should be noted that I have encountered a non-zero number of bugs due to getters/setters.
|
the getters suck flame war is oozing with nerdiness. i like it.
|
On May 30 2012 01:26 typedef struct wrote: This debate says a lot about object-oriented programming in general. You'd never find this kind of disagreement about a fundamental concept in a functional language/style.
Moving the functionality into the class you are accessing (the technique getdatsu posted) is only the correct solution if said functionality is something the class is directly responsible for. If not, you're just adding more responsiblities to the class (in violation of the Single Responsiblity Principle).
Friend is almost never the answer, and if you're new to C++ you should forget that keyword exists (as evidenced by the fact that plenty of good OOP languages don't have it).
Providing a getter method is usually the best solution. You can see this by exploring one of the many well-written open-source OOP code bases out there. You will see getters/setters used, but not abused.
It's pretty easy to tell if you're overusing getters/setters, because you'll get f*cking sick of writing them and be tempted to just make everything public. If you run into this situation, you probably have too few classes for what you are trying to do, and should break some of them up.
C++/Java/C#.net are pretty bad OO languages and are based on the Strousup stream of OO which was terribly designed in the first place.
There are much better functional/OO hybrids out there these days, but even Smalltalk which was the original true OO language (yes Simula was the first OO but I'm talking about in a practical sense) works completely different to mainstream OO languages.
See Ruby as a great example of a fully OO language which is based on Allen Kay's OO principles rather than Strousup's OO principles.
|
On May 30 2012 08:15 RoyGBiv_13 wrote:Show nested quote +On May 30 2012 07:38 Millitron wrote: Speaking of heated debate topics, why is GO TO considered such a bad feature for a language to have?
I mean, I get that if you are completely careless with it, you can access memory that hasn't been allocated for your program, but it's extremely hard to screw up that bad. You almost have to force it to happen.
The thing is though, GO TO provides an effective way of exiting complex control structures. It is a gigantic pain to try to get a large group of nested for-loops to terminate early without GO TO, but with GO TO, it can be done with the addition of a single if-statement.
I was making a Turing Machine simulator for a class I was taking. The simulator was written in Java. The state of the machine ended up being stored in a 4D array, meaning it had to be accessed by a nesting of for-loops. It was such a pain to break out of those loops without GO TO. Work for a company that builds a C/C++ compiler. Here is my chiming in on why getters/setters is bad from a performance standpoint (thus design), and also why you should be glad GOTO has been wiped. These practices are not mainstream, and have for the most part been purged from the global corporate and open source code base, and for a reason! It is dismal that getters/setters is being snuck back in by high school CS teachers and design by committee curriculum. (I do not mean that any getter or setter is bad design, just that ALL classes MUST have getters/setters, and ALL variables MUST be private) Lets talk performance. Ill start with GOTO because its an easy target: Back in ye olden BASIC times, GOTO's were the go to (heh) method for program flow. This was alright, and did not typically affect speed of computations nor code size in any significant manner, because the code assembled almost directly into its literal machine code translation, with no optimizations. Then came Dennis Ritchie and C. A compiled language will look almost nothing like itself when turned into machine code. Most notably is the inclusion of the stack and functions. Function calls replaced the LABEL A -> GOTO B -> GOTO A spaghetti by including the address of the branch to instruction onto the stack, and branching to the stack popping upon returning form a function. This is incredibly faster as a processor optimized for branch prediction would almost always have the next instruction loaded into the cache, compared to the GOTO method. This is one of many reasons why people tell you to never use GOTO under any circumstance. It may seem efficient at the time, but in reality, it provides even more complexity where well thought out program flow would be better to begin with. For Getters/Setters, the compiler will optimize out getters and setters 90% of the time and turn them into inline functions, which will be effectively what you wanted to put in your code anyway. the other 10% of the time, in things such as generic classes (http://en.wikipedia.org/wiki/Template_(C%2B%2B) )or getting/setting 32-bit or 64 bit structs that would like to be optimized into registers , you will feel a significant performance hit by using this sort of code design. It is not poor design to completely neglect getters and setters from code, as they definitely have their design uses for abstraction. It is poor design to write code that needlessly complicated where a more understandable alternative exists that is also closer to what the cpu actually does. It should be noted that I have encountered a non-zero number of bugs due to getters/setters.
I agree, but tl;dr there was a new movement to have only one entry-point and one-exit point in blocks code. Dijkstra wrote an article called "goto statement considered harmful" (which due to its success, spawned a whole lot of elitists to create similar articles in the same vein but stupid) which championed the "structured programming" movement. Basically he said use functions and procedures rather than goto statements because goto statements create spaghetti code.
|
Any suggestions for a c++ compiler? I don't need anything special, just something that works and is free (at least i'm assuming there are free ones beyond trial periods). I could just go down the list of them on wikipedia, but I figure asking TL is better than guess and check.
|
|
LLVM/Clang is another one
|
On May 30 2012 10:12 hacklebeast wrote: Any suggestions for a c++ compiler? I don't need anything special, just something that works and is free (at least i'm assuming there are free ones beyond trial periods). I could just go down the list of them on wikipedia, but I figure asking TL is better than guess and check.
As mentioned before, Microsoft Visual Studio C++ Express is probably the best, free IDE available for C++ on Windows; however, it essentially only compiles for Windows. If you're specifically looking for a multi-platform compiler, I would recommend Qt.
|
On May 30 2012 10:12 hacklebeast wrote: Any suggestions for a c++ compiler? I don't need anything special, just something that works and is free (at least i'm assuming there are free ones beyond trial periods). I could just go down the list of them on wikipedia, but I figure asking TL is better than guess and check.
Get codeblocks, its more lightweight than VC++ and crossplatform and easy to use. Although I wouldn't recommend it for anything other than for C/C++. You can even get a portable version that you can just stick on usb.
It uses the gnu gcc compiler.
|
On May 30 2012 11:45 Zeke50100 wrote:Show nested quote +On May 30 2012 10:12 hacklebeast wrote: Any suggestions for a c++ compiler? I don't need anything special, just something that works and is free (at least i'm assuming there are free ones beyond trial periods). I could just go down the list of them on wikipedia, but I figure asking TL is better than guess and check. As mentioned before, Microsoft Visual Studio C++ Express is probably the best, free IDE available for C++ on Windows; however, it essentially only compiles for Windows. If you're specifically looking for a multi-platform compiler, I would recommend Qt. There's also the Eclipse C++ plugin. It has all the nice features of Eclipse for Java, but for C++.
|
On May 30 2012 09:47 sluggaslamoo wrote: C++/Java/C#.net are pretty bad OO languages and are based on the Strousup stream of OO which was terribly designed in the first place.
There are much better functional/OO hybrids out there these days, but even Smalltalk which was the original true OO language (yes Simula was the first OO but I'm talking about in a practical sense) works completely different to mainstream OO languages.
See Ruby as a great example of a fully OO language which is based on Allen Kay's OO principles rather than Strousup's OO principles.
Can you, please, point me to some good reads on these topics?
|
On May 31 2012 20:57 ForgottenOne wrote:Show nested quote +On May 30 2012 09:47 sluggaslamoo wrote: C++/Java/C#.net are pretty bad OO languages and are based on the Strousup stream of OO which was terribly designed in the first place.
There are much better functional/OO hybrids out there these days, but even Smalltalk which was the original true OO language (yes Simula was the first OO but I'm talking about in a practical sense) works completely different to mainstream OO languages.
See Ruby as a great example of a fully OO language which is based on Allen Kay's OO principles rather than Strousup's OO principles. Can you, please, point me to some good reads on these topics?
The conclusion I made is from years of reading lots of different books/articles/websites, trying many different languages, understanding paradigms, knowing about the guys who invented each language, designing my own languages with PEGs, etc. I don't think you will be able to find an article on what I said specifically.
The best starter point is to look up Alan Kay and Bjarne Strousup, the inventors of Smalltalk and C++ respectively.
If I were to come up with a very brief reason to my conclusion,
Alan Kay was the guy who championed OO in the first place, then Strousup created C++, and Kay thinks [in the most euphemistic way possible] C++ was "not what he had in mind".
Java is based on C++, but tries to simply/fix C++ by constricting the paradigm, for example many interfaces/one concrete class inheritance, in order to avoid multiple inheritance problems like cyclic inheritance. IMO this is one of the really terrible fixes Java did to get around those problems.
C# used to be called J#, until Sun didn't want Delegates to be a part of Java. So Microsoft branched off and created C#, which basically started off as Java, with Delegates. Being based on Java, its only a marginal improvement on its older brother, when compared to other languages.
These 3 languages is what I dub as part of the "Strousup" stream of OO, the one most people know and understand. The less understood form OO comes from Alan Kay, the inventor of OO and Smalltalk. Its no surprise, that OOP makes a ton more sense when using Smalltalk than when using C++. What Java is to C++, Ruby is to Smalltalk. Matz was inspired by a lot of Kay's principles when he invented Ruby.
I don't rate a language by its features, I rate it by its foundation, when a language has a good foundation, it doesn't need a million features to make it good. You can polish a turd, it still doesn't stop it from being a turd.
|
|
|
|