| devonrevenge (891) | |||||||
|
Only i cant find a tutorial on it, Now i could ask in a java forum but you will find, just like i did, that no one can make a coherent forum for java that makes sense is well written and easy to use! What I wanted to do is have an object that had a member function that i could store any amount of strings on, it also has a name in which i could refer to that list with. so i would have a cuisine object, it would have its title and recipie. so in the main menu i could add a title followed by the recipe, this object would be stored on a list, i could also enter the name of the recipe and get said list. This is the ugly monster I created, this is my first java program please font laugh at my spelling it hurts deep, way down in my soul. Oh yeah and i know its fundementally flawed
I call it all wierdly in main too
lastly im sure this class is fine and is basic stuff, im just putting it here cos i know you guys can still find things in it that i could do better...
| |||||||
|
Last edited on
|
|||||||
| Luc Lieber (985) | |||||
* Should note that I didn't compile it. | |||||
|
Last edited on
|
|||||
| L B (3805) | |
| @Luc Lieber: I just want to thank you so much for putting braces on their own lines. | |
|
|
|
| Luc Lieber (985) | |
|
I do that intentionally to piss off Java-noids. :D *yearrghs! | |
|
|
|
| Oria (71) | ||
I think all Java users should convert to C# and then Java could seize to exist. ;-) | ||
|
|
||
| ResidentBiscuit (2645) | |
|
Heh, I'm currently writing some code for a class that uses Java, and the book and the professor both put braces on the same line as the initiating statement but ain't nobody got time for dat. Braces on their own line for life! | |
|
|
|
| BHXSpecter (982) | |
| Wow, never knew anyone to be so anal about brace location. I always do it on their own line, but that is because that is how I prefer to do it. I've seen guys that do C++ and do int main(){ or datatype functionname(params){ in their code. It is the programmer's preference, just like a guy could be annoying and put his entire program on just one line of code. | |
|
|
|
| Luc Lieber (985) | |||
Afraid not. (with Java) http://www.oracle.com/technetwork/java/codeconv-138413.html Failing to follow the Sun (now Oracle) bible will get you instantaneously labeled as a heretic. Aaaanyhow... @devonrevenge -- any questions? | |||
|
Last edited on
|
|||
| shacktar (1143) | |||||||||
Can't you just do the following?
Like the poster on StackOverflow said, you're not keeping track of the index with respect to the size of objlist. You could use the Java for each loop to not have to keep track of the current index. Here is how I would do it.
| |||||||||
|
Last edited on
|
|||||||||
| BHXSpecter (982) | |||||
I've been labeled and called worse than a heretic. For example, all my Java code for my first few apps are similar to this:
[edit] mismatched code tags with quote tags | |||||
|
Last edited on
|
|||||
| L B (3805) | |
| The only thing wrong with that is your placement of the [] for args. It's valid syntax, but it doesn't quite look right... | |
|
|
|
| BHXSpecter (982) | |||
Yeah, I should have copy and pasted it. I typed it by hand and just did args[] out of habit (thinking of the C++ argv[]), but the file is String[] args like it is supposed to be. Though, it compiles with both forms as I just foud out :-/, figured it would have sent a error or something. | |||
|
Last edited on
|
|||
| rapidcoder (736) | ||
Guess what. We put braces on their own lines. I don't like it, but this is the standard that runs in our 99% Java / 1% C++ codebase. I guess this is because the initial coders who started the project were C++ and PHP coders that just switched to Java. We still have some code remaining from that times and it is terrible (still finding lots bugs in that old code after a few years) but no-one is courageous enough to rewrite it properly. :P The most important thing is to keep it consistent. And Sun/Oracle did a lot of good work there - at least most of Java code out there places opening brace on the same line and uses 4-char indentation. Much better than many projects in other languages where everybody wanted to invent their own style of indentation, spacing, basic structures as lists strings... (Qt - I'm pointing my finger at you). As for the original poster's code: 1. avoid static variables; really try to write your code without static at all - believe me, it is possible to write any code with one and only single static in main; I'm sure that decision alone will make your code immediately much, much better (you should avoid static in C++, too). 2. Name classes from capital letter. Code is to be read by programmers and all programmers expect Java classes names to be capitalized (the same applies for braces - if you write C++ code, you can do as you wish, because there is no official convention/code style standard). | ||
|
Last edited on
|
||
| devonrevenge (891) | |
|
cool thanks no questions cos im still too nooby to know better, its good to know the correct way its done AND the correct way of doing what i was doing, i did look at c# first, it is easier to learn and more intuitive its also exactly the same!! I heard fortran was different but forget that...for now. EDIT: YOU GOT TO FOLLOW CONVENTIONS!? Thats not a healthy state of mind for creative types, in the long run understanding a code you know lets say english, written lets say in verse rather than in a yorkshire accent is only going to help you speak better more beautiful english | |
|
Last edited on
|
|
| rapidcoder (736) | |
|
if you want to piss off everyone on the team, yep, write in creative code style. | |
|
|
|
| ResidentBiscuit (2645) | |
| You can have creative code that follows formatting convention. The formatting has no effect on the actual code you write. | |
|
|
|
| L B (3805) | |
| You can use an IDE that formats your code the way to like and then just change the formatting, have your IDE autoreformat it, and then push a commit with the proper formatting, then set your IDE back to your preferred formatting. | |
|
|
|
| devonrevenge (891) | |
| thanks shaktar that was where i was coming from cool. | |
|
|
|
| xerzi (605) | |
| So much for individuality when it comes to programming in Java. I agree that a single project should follow a convention but as per a language I'm surprised Java doesn't throw errors if the source doesn't follow the naming convention. | |
|
|
|
| devonrevenge (891) | |||
so what have i done wrong here?
| |||
|
|
|||