Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Abandoned Projects

This thread is locked; no one can reply to it. rss feed Print
Abandoned Projects
Specter Phoenix
Member #1,425
July 2001
avatar

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
avatar

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. :)

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Dario ff
Member #10,065
August 2008
avatar

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. ;D

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Matthew Leverton
Supreme Loser
January 1999
avatar

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
avatar

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
avatar

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
avatar

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. :P 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.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

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. :P

Matthew Leverton
Supreme Loser
January 1999
avatar

Dario ff said:

It's not about overly brief, it's about NOT replacing an already implemented operator with no good reason.

James is probably referring more to things like:

return (b = func1(a + func2(func3() * magic_number) / func4())) ? b : func5(b);

That ends up looking like this.

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
avatar

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.

-->
Graphic file formats used to fascinate me, but now I find them rather satanic.

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
avatar

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
avatar

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:

  • Just because you get paid to do something doesn't mean you're good at it; some shops hire based on actual skills, but there are plenty of places where you can get pretty far with a combination of a college degree, meaningless fact memorization, and personal marketing skills.

  • As a professional, there are always real-world constraints on your programming: you are on a budget (which means you can't sink infinite amounts of time into a task), you are on a deadline, there's an existing codebase you have to work with, the specifications are unclear, contradictory, or outright impossible, there's other team members with incompatible ideas, etc. etc. Sometimes, the proper solution would require a month of feature-freeze, and the customer cannot afford that, so you start out with a hack and try to gradually phase toward the proper solution. Sometimes, you are looking at a ten-thousand-LOC file full of puss, and you have to implement a small change; you can't rewrite all the puss in the time you have, so you read enough of the mess to make sense of it, clean up what you reasonably can, and do what it takes. Since you have to at least partially go with what's there, the code you add isn't going to be pretty, but it will work, and it will be a bit better than what was there.

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

  • Similar structures. OOP with its class hierarchies and locally-imperative approach is very similar to how a typical business is structured, and the way functionality is encapsulated and bundled through several layers looks a lot like the way management layers distribute and delegate tasks. Because of these similarities, OOP programmers and designers have an easier time communicating with non-technical managers; given an intelligent non-technical management type, I could easily explain an OOP design in terms they can understand, but I'd have a much harder time doing it with an FP design - simply because there isn't anything in the organisation of a business that resembles partial function application, closures, monads, or any other core FP concept.

  • Tradition. The business world has used imperative and structured programming since the early days of COBOL, and OOP, which inherits most of this heritage, is a logical extension - after all, a class is just a subprogram with its own local state, and a method is just a procedure with a scope.

  • Available programmer material. The way things are at the moment, OOP programmers are plenty, but FP programmers are scarce. Finding a few dozen code monkeys to hack on your Java codebase is easy (though you get what you pay for), doing the same for a Clojure application is much harder. Try outsourcing a PHP project, then try outsourcing a comparable project written in CL. Try C# vs. F#. Of course, if it's excellence you're looking for, then the paradigms are probably almost on par, and programmers in that category will be more likely to be comfortable with either, and most of them will have developed a hybrid style that takes advantage of many different paradigms.

  • Tools. Let's face it: OOP has the better tools. When I do OOP, say, in C++ or PHP, I miss an interactive environment like Common Lisp's REPL, Haskell's ghci, or Python's interactive interpreter, but other than that, there are more and better tools to choose from, and almost any tool you could use for a functional language is also available for OOP, either because it's language-agnostic, or because someone has written an equivalent. Of course, the fact that functional languages tend to come with less boilerplate and better language features to reduce cruft somewhat alleviates this (a lot if you ask me), but it remains that the comfort of a modern IDE is at least significantly reduces for FP languages.

  • Trust. The above points combined also lead to a higher level of trust among business users for OOP. Given the choice, they rather trust a programming paradigm that has shiny tools, is used throughout the industry, and can be explained in layman's terms without leading to utter confusion, than one that seems to require a PhD to fully understand, has only text-based tools that look like random gibberish, is used mainly in academia (thus, by PhD's), and even confuses experienced programmers. And I can't really blame anyone, even though FP may actually often be the better solution, bottom line.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

verthex
Member #11,340
September 2009
avatar

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
avatar

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

#SelectExpand
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

#SelectExpand
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

#SelectExpand
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

#SelectExpand
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:
ex:

    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).

Specter Phoenix
Member #1,425
July 2001
avatar

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

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?

...also, if we're all patronising enough he might get is arse into gear and write a game out of pure embarrassment. :P

Agreed.

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.:D
-->
Red hot tentacle love.

Need I say more? ;D

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.

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...)"
"I was in a casino, minding my own business, and this guy came up to me and said, 'You're gonna have to move. You're blocking a fire exit.' As though if there was a fire, I wasn't gonna run. If you're flammable and have legs, you are never blocking a fire exit... ...Unless you're a table."
-Mitch Hedberg (R.I.P.)
"Quit: (+[WG]sPiKie) (Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x].)"



Go to: