|
Abandoned Projects |
Specter Phoenix
Member #1,425
July 2001
|
Tobias Dammers said: Bad code is bad code, and good code is good code. Sad part is that when you see code from professionals you realize that a lot of pros use a lot of bad code.
|
23yrold3yrold
Member #1,134
March 2001
|
Specter Phoenix said: Sad part is that when you see code from professionals you realize that a lot of pros use a lot of bad code. I was amused by this, especially since my current work project includes a client-server setup with client-side caching, SQL, and other stuff I'm pretty dumb about but still do better than this. -- |
Dario ff
Member #10,065
August 2008
|
Forgot about catching up with tdwtf for a while: Quote: private static bool InvertBool(bool org) { bool returnValue = false; if (org) { returnValue = false; } if (!org) { returnValue = true; } return returnValue; }
Oh my. TranslatorHack 2010, a human translation chain in a.cc. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
That's obviously much clearer than My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Matthew Leverton
Supreme Loser
January 1999
|
Dario ff said: Forgot about catching up with tdwtf for a while: Lots of programmers don't understand booleans, return values, function parameters, etc. I saw lots of things like this as a GA: bool rv; int i; i = 42; rv = some_function(i); return rv; The reason is they would always think that when you call a function that takes a parameter named i, that you would also have to send it a parameter named i. And directly returning the value of one function call just blew their minds. |
james_lohr
Member #1,947
February 2002
|
However, one should also be aware that there are occasions where cleverly reducing an expression to its simplest form may detract from readability. This is particularly true when implementing pieces of business logic.
|
verthex
Member #11,340
September 2009
|
James Lohr said: However, you should also be aware that there are occasions where cleverly reducing an expression to its simplest form may detract from readability I usually create my classes one function at a time.
|
Matthew Leverton
Supreme Loser
January 1999
|
Really the code always looked like: bool rv; // bool variable named rv int i; // int variable named i i = 42; // set i to 42 rv = some_function(i); // set rv to some_function(i) value return rv; // return rv But yes, overly brief code can be hard to read as well. |
Dario ff
Member #10,065
August 2008
|
Seeing a ! should be as natural as seeing + in code. It's not about overly brief, it's about NOT replacing an already implemented operator with no good reason. I understand ignorance on some functions of the standard(for example, I really didn't know there was sscanf for reading values from strings nearly a year ago), but the author of the snippet clearly knew the operator existed... he even used it in the definition. TranslatorHack 2010, a human translation chain in a.cc. |
james_lohr
Member #1,947
February 2002
|
verthex said: I usually create my classes one function at a time. What has that got to do with anything? Dario ff said: Seeing a ! should be as natural as seeing + in code. Of course. Let me just be clear that I was most certainly not implying that Matthew's example is one where verbosity aids readability.
|
Matthew Leverton
Supreme Loser
January 1999
|
james_lohr
Member #1,947
February 2002
|
Yeah. However, there are less clear-cut cases. For example, suppose the CEO comes along and says: "Write me a little program which books me a taxi if it is not a Monday (because I cycle in on Mondays), and if the trains are not running." bookATaxi = !isMondayToday && !trainsAreRunning; You could then simplify it to this: bookATaxi = !(isMonday || trainsAreRunning); ..now suppose you come back to the code a month later, because you want to remember what it was exactly that the CEO asked you to implement. The second is decidedly more difficult to reason about (maybe not to you, but it certainly would be if you worded it back to the CEO). This is not a particularly good example, but I'm sure you can think of more extreme cases. In fact I'm guilty of simplifying a few chunks of boolean logic to half their original size at the cost of making it nearly impossible to understand what it actually means afterwards. Don't get me wrong: simplifying boolean logic can be extremely powerful and in most cases will actually give a better insight into what the original statement really means. I'm just saying that there are some cases where a bit of verbosity is better.
|
Sirocco
Member #88
April 2000
|
Being clever, in the real world, is only great when you want to flex your programming fu and don't have to worry about ever revisiting the code. My boss runs in circles all day because be produces undocumented, intricately designed code that is never meant to be changed or looked at. I produce well-documented code that is designed with practicality in mind. When the inevitable change requests start rolling in, I finish my mods before anyone else. Work smarter, not harder. Everything in moderation. Etc. It's perfectly fine to make mistakes, as long as you learn from them. Doing the same retarded thing over and over is the mark of a PHB. --> |
james_lohr
Member #1,947
February 2002
|
This is half the reason why functional languages don't really cut it in industry: elegance and cleverness for the sake of elegance and cleverness is all very well in academia, but in the real world all it really achieves is unnecessary bewilderment.
|
verthex
Member #11,340
September 2009
|
James Lohr said: What has that got to do with anything? It makes things easier to read. I have one class for printing, one for calculating the same thing 50 million times, and one for stupid shit that gets repeated over and over again. I guess you've never broken down your code to make it easier to read.
|
james_lohr
Member #1,947
February 2002
|
verthex said: It makes things easier to read. As does a pair of glasses. We were talking about statements and expressions. Classes have no bearing on the conversation, and we could quite feasibly be discussing a language that doesn't even support classes. You do this all the time, and if you want me to stop picking you up on it, then start thinking before you post. If a random vaguely related thought flashes before your mind that you feel the need to blurt out it onto the forum, please qualify it as such.
|
Tobias Dammers
Member #2,604
August 2002
|
Specter Phoenix said: Sad part is that when you see code from professionals you realize that a lot of pros use a lot of bad code. Two reasons:
James Lohr said: This is half the reason why functional languages don't really cut it in industry: elegance and cleverness for the sake of elegance and cleverness is all very well in academia, but in the real world all it really achieves is unnecessary bewilderment. Functional Programming is more than cleverness and elegance for its own sake; there are actual practical benefits, such as simplified static analysis and formal proof-of-correctness, simplified unit testing, easier parallelization and distribution of execution, etc. etc; however, OOP and enterprise programming get along very well, and it's hard for any other paradigm to break into this marriage. The reasons are many, but I guess the most important ones would be
--- |
verthex
Member #11,340
September 2009
|
James Lohr said: As does a pair of glasses. We were talking about statements and expressions. Classes have no bearing on the conversation, and we could quite feasibly be discussing a language that doesn't even support classes.You do this all the time, and if you want me to stop picking you up on it, then start thinking before you post. If a random vaguely related thought flashes before your mind that you feel the need to blurt out it onto the forum, please qualify it as such. James you trolled my thread the last time. Remember your question, re-read the thread! Quote: What specifically are you trying to hash that you have having trouble with? I mentioned it in the first post!
|
Specter Phoenix
Member #1,425
July 2001
|
Currently working on a pure terminal address book app. Right now I have a few things missing that I hadn't figured into the original paper design (yes I actually set down and laid it out on paper to an extent, which I never do). I normally just tell myself, "I want to make <app/game>.", open IDE and terminal and start writing code without thinking it out. This time that isn't the case. It's an abandon project I decided to pick up from scratch and try actually thinking it out before I started coding. Parts of the code is test code til I get everything addressed (no pun intended). Been bouncing back and forth between the book files, menu files, and main file. Do to size I put the code in a spoiler to not fill so much of the screen. addrBook.h 1#ifndef ADDRBOOK_H
2#define ADDRBOOK_H
3#include <string>
4
5class addrPage
6{
7 public:
8 void setName(std::string first, std::string last);
9 void setAddr(std::string addy);
10 void setPhone(std::string phone);
11 void printAddress() const;
12 private:
13 std::string firstName;
14 std::string lastName;
15 std::string homeAddr;
16 std::string personPhone;
17};
18
19class addrBook
20{
21 public:
22 void setInfo(int page, std::string first, std::string last, std::string addr, std::string phone);
23 void printData() const;
24 void turnPageForward(int& pgNum);
25 void turnPageBackward(int& pgNum);
26 private:
27 addrPage addressPage[20];
28};
29
30#endif
addrBook.cpp 1#include "addrBook.h"
2#include <string>
3#include <iostream>
4
5void addrPage::setName(std::string first, std::string last)
6{
7 firstName = first;
8 lastName = last;
9}
10
11void addrPage::setAddr(std::string addy)
12{
13 homeAddr = addy;
14}
15
16void addrPage::setPhone(std::string phone)
17{
18 personPhone = phone;
19}
20
21void addrPage::printAddress() const
22{
23 std::cout << firstName << " " << lastName << "\n"
24 << homeAddr << "\n" << personPhone << "\n\n";
25}
26
27void addrBook::setInfo(int page, std::string first, std::string last, std::string addr, std::string phone)
28{
29 addressPage[page - 1].setName(first, last);
30 addressPage[page - 1].setAddr(addr);
31 addressPage[page - 1].setPhone(phone);
32}
33
34void addrBook::printData() const
35{
36 for(int i = 0; i < 4; i++)
37 {
38 addressPage[i].printAddress();
39 }
40}
41
42void addrBook::turnPageForward(int& pgNum)
43{
44 addressPage[pgNum++];
45}
46
47void addrBook::turnPageBackward(int& pgNum)
48{
49 addressPage[pgNum--];
50}
addrMenus.h #ifndef ADDRMENUS_H #define ADDRMENUS_H #include "addrBook.h" void menuSystem(addrBook& Book); void addMenu(addrBook& Book); void editMenu(addrBook& Book); void deleteMenu(addrBook& Book); void viewMenu(const addrBook& Book); #endif addrMenus.cpp 1#include "addrMenus.h"
2#include <iostream>
3
4void menuSystem(addrBook& Book)
5{
6 int choice;
7 std::cout << "addrbook banner\n";
8 std::cout << "enter a number to do:\n";
9 std::cout << "1) Add \n";
10 std::cout << "2) Edit\n";
11 std::cout << "3) Delete\n";
12 std::cout << "4) View\n";
13 std::cin >> choice;
14 switch(choice)
15 {
16 case 1:
17 addMenu(Book);
18 break;
19 case 2:
20 editMenu(Book);
21 break;
22 case 3:
23 deleteMenu(Book);
24 break;
25 case 4:
26 viewMenu(Book);
27 break;
28 default:
29 std::cout << "Not a valid choice.";
30 break;
31 }
32 std::cout << "\n";
33}
34
35void addMenu(addrBook& Book)
36{
37 std::cin.ignore(100, '\n');
38 std::string fName, lName, address, phone;
39 std::cout << "Enter First name: ";
40 getline(std::cin, fName);
41 std::cout << "Enter last name: ";
42 getline(std::cin, lName);
43 std::cout << "Enter address: ";
44 getline(std::cin, address);
45 std::cout << "Enter phone: ";
46 getline(std::cin, phone);
47 Book.setInfo(1, fName, lName, address, phone);
48}
49
50void editMenu(addrBook& Book)
51{
52 int page;
53 std::cout << "Edit which page?\n";
54 std::cin >> page;
55
56
57}
58
59void deleteMenu(addrBook& Book)
60{
61 std::cout << "Delete which page?\n";
62}
63
64void viewMenu(const addrBook& Book)
65{
66 std::cout << "Printing book to screen and file...\n";
67 for (int i = 0; i < 5; i++)
68 {
69 Book.printData();
70 std::cout << "\n\n";
71 }
72}
addrMain.cpp 1#include "addrBook.h"
2#include "addrMenus.h"
3#include <iostream>
4
5bool PISS_OF_BAMCCAIG = 1; // got to have my running gag in my code
6
7int main()
8{
9 int pick;
10 char answer;
11 bool done = false;
12 addrBook myAddrBook;
13
14 menuSystem(myAddrBook);
15
16 while (!done)
17 {
18 std::cout << "Are you done? (y/n): \n";
19 std::cin >> answer;
20 switch(answer)
21 {
22 case 'y':
23 done = true;
24 break;
25 case 'Y':
26 done = true;
27 break;
28 case 'n':
29 done = false;
30 break;
31 case 'N':
32 done = false;
33 break;
34 default:
35 std::cout << "Enter 'Y' or 'N'!\n";
36 break;
37 }
38
39 if (!done)
40 {
41 menuSystem(myAddrBook);
42 }
43 }
44
45 return 0;
46}
|
jmasterx
Member #11,410
October 2009
|
Just a tip: Setters in general should take a const reference: void setName(const std::string& first,const std::string& last); void setAddr(const std::string& addy); void setPhone(const std::string& phone); This is because you do not want to allocate a new string on the heap and you wont modify the data being passed (const). Agui GUI API -> https://github.com/jmasterx/Agui |
Specter Phoenix
Member #1,425
July 2001
|
Ok, thanks for that. My CS book I'm using as reference doesn't say anything about that, just to use reference on get functions with multiple parameters or return values needed.
|
Emanresu
Member #12,510
January 2011
|
Matthew Leverton said: It's not like we are discussing somebody who is giving up after a few weeks or after the first hurdle. He's been at it for over ten years with almost no results. You are wasting your time if you think your encouragement will help him succeed. His lack of belief in himself comes from the reality that he doesn't have what it takes to be a competent programmer.That doesn't mean he's stupid or that he isn't trying hard enough. It means his brain isn't "wired correctly" for programming, and he ought to pursue other tasks. If he wants to make games, then perhaps he should just focus on modding games via level editors. It's much more kind to give him realistic advice than to pat him on the back or kick him in the butt. And when he starts doing things he's good at, his self confidence and attitude will improve.Telling somebody that they ought to be able to do something that they cannot do despite trying very hard is only going to make his or her depression and lack of confidence worse. When you come to the understanding that you have limitations (like everybody else), it's much easier to handle defeat.And even if he could eventually do it, it's dumb to spend a thousand times more effort than a "regular person" does to accomplish the same task. e.g., If it took me two hours every morning to put on my own socks, then I would get somebody else to do it for me. That doesn't mean I'm a quitter or have no faith in my abilities, but that I'm realistic about how I should spend my time. Like I said earlier, I don't really know him, (or anyone here on Allegro.cc for that matter), all that well. I don't know how long he's been working on anything at all. Since it's taken him 10 years to do nothing, perhaps it is time for him to try another approach. Kinder to give him realistic advice? Shall we call Dr. Kevorkian then? James Lohr said: ...also, if we're all patronising enough he might get is arse into gear and write a game out of pure embarrassment. Sirocco said: I always laugh a little when I come across that word (placebo). It sounds like some sort of Japanese demon; perhaps the small, perverted sort that flies around sneaking peeks up girls' skirts. Need I say more? weapon_S said: As someone who is struggling himself with getting a decent game done, I can say: it's better to have that works, than to have perfection that doesn't exist. Agreed. Specter Phoenix said: Currently working on a pure terminal address book app. Right now I have a few things missing that I hadn't figured into the original paper design (yes I actually set down and laid it out on paper to an extent, which I never do). I normally just tell myself, "I want to make <app/game>.", open IDE and terminal and start writing code without thinking it out. This time that isn't the case. It's an abandon project I decided to pick up from scratch and try actually thinking it out before I started coding. That's how I am. I can't stand pseudo coding or flow charting. I'm glad you're going for a console only application right now. I was thinking about what you've been saying and I feel that you were trying to eat some beef one cow at a time. Have a few steaks or burgers at first, then work your way up. What I was going to recommend to you was that you avoid physics all together and use logic to move the ball around. And also avoid using sound, mouse input, graphics and keyboard input all together at first. Make a console pong clone to get your logic working properly. Fact is, don't even make it 2d at first, make the ball stay all on one line. Get that working well before you take on larger tasks. You said logic was one of your biggest problems after all. I also recommend that you don't post your code that has your logic in it if you can avoid it. Sure, post it when you can't find out why it won't compile or you get massive errors that shouldn't occur, but try to avoid posting your logic. Why do I say that? Because people may just give you the answer to your problem instead of helping you learn what you're doing wrong. "* Entoutcas has quit IRC (Quit: And the Lord said unto John; Come forth and receive eternal life. But John came fifth and won a toaster...)" |
|
|