I'm a hobbyist programmer. I wrote a small piece of game code (about 300 lines, 2 files, 1 class, 2 functions), and a friend of mine, who is a professional software developer, pulled it from my github.
He handed it back to me two days later, and it is now like 20 files, 10 classes, 500 lines of code, everything is created dynamically, and main function that has like 4 lines in it.
He modernized it by using using cutting edge cross-functional development techniques.
Camden Scott
in laymans terms
he crapped it up
Leo King
he pood init
John Wilson
Prefer object composition over inheritance, and keep your main() function as simple as possible.
That said, if he has 20 files and 10 classes with only 500 lines of code, he's almost certainly retarded.
Jace Scott
>500 lines across 20 files Sounds like Java and that's before we even get to the Sup Forums boogeyman (OOP).
Brayden Thomas
Is it object-oriented?
Brayden Wilson
>▶ It is C++
Elijah Flores
>and keep your main() function as simple as possible Why though? I'm starting to program and if this is a good habit, I'd like to start practicing it but knowing why I'd do it.
Blake Murphy
Link to your original repo and the reup from this supposed "pro" please.
Gabriel Ward
Autism
Samuel Flores
Makes it easier to understand what the program does i.e. gives you a summary of major function calls made.
Ryan Martin
Learn about software design pattern, user! I guess His main function most likely just need to instantiate a controller class or a factory class and then run it.
Nathaniel Wood
Your main function should be very clear and make calls to some methods with well thought out, high level names. Just makes it easier for someone who didn't write it to understand since if you work in industry youll be working with a ton of shit lords.
Dylan Jenkins
dont listen to these fuckers. it is completely anecdotal to the program
I don't think this word means what you think it does.
Gavin Sullivan
yes it does
it means that it is completely dependant on what type of program it is
Charles Ortiz
Idiot OOP code-moneys think you need to put every class in it's own file, and sometimes every function and codeblock too, and if your program doesn't take 2 minutes to start, it isn't enterprise quality.
Dylan Wright
Every function call should be in its own file.
Caleb Hughes
Well, you see a function should only do one thing and be easily described by its name. Even on non-oop program you shouldn't have that long main function. What's the benefits? - other programmer can easily tell what a function do - can be reused on other occasion. - testable using unit test. As I said before, learn this thing called design pattern, boy
Not the guy who called you out, but no, no it doesn't.
Colton Bennett
>not placing every statement in its own file
You don't want to be able to read your code from the file manager?
Parker King
>trying to warp the definition of a word that kind of makes sense but actually doesn't in the context that you used it
Ryder Davis
>being this autistic
Benjamin Cox
I do this with the thought that my main class essentially scripts things while the methods actually perform work. when looking at main it is as close to spoken english as is reasonable
Mason Gonzalez
>fuck I lost >I know I'll call him autistic
Landon Reyes
STOP PLS YOU ALRDY WON
Adam Butler
Refactored code is much more readable.
Jose Edwards
>change a single character >have to recompile the entire program
Zachary Young
>What sorcery is this?
software development. read a book bitch
Jaxon Howard
Their culled ebuk beesh.
Robert Barnes
I actually prefer to base32 encode each statement into the hostnames of all the machines on my network ordered by ip address and use subnetting for blocks and control flow.
What a dick, the cleaned up code isn't that bad, at least not as far as "the most horrifying monstrosity to ever touch Github", talk about being overdramatic. >holy shit, this guy split up some spaghetti C++/C franken-code into like 5 manageable C++ classes!!! wtf!!!
Looking through his github I see he's got pretty much no OOP experience, what a surprise. I guess if you've never touched OOP something simple like this probably would frighten you.
Connor Thomas
Can we get the link? Current on the code
Joshua Miller
Non-coder here but isn't the point of corporate coding to obfuscate as much as possible so you get to keep your job?
Asher Gutierrez
I'm not sure why people get worked up about numbers of lines and numbers of files. These aren't metrics of anything important. The fact that your version only has 2 functions leads me to think you either aren't doing very much or you crammed a ton of logic into a rigid organization that's probably hard to understand, extend, or maintain.
Isaiah Gray
no.
that's how you get fired.
it's 2017, people don't live in a tech vacuum anymore.
Asher Walker
A easy tip to improve is: NEVER WRITE SOMETHING A THIRD TIME Copy paste counts too ! Use functions instead In many cases its ok to write something twice, but never a third or fourth time.
Noah Baker
Tbh my code can look like either of those or anything in between depending on how large or modifiable I intend for it to be/how lazy I feel Although the 'pro' not having fucking multiline full-description comments on everything makes me feel better about hating the people who do.
Grayson Nelson
dont use clases or functions. just retype everything and keep it all in the main.
Matthew Ortiz
>friend tries to help you learn >you post his code on Sup Forums Of course was going to happen OP. Be a little nicer to your friends.
Easton Jackson
lol well he's a busy guy, and I wanted to get some insight on why he would make some of these changes.
Nicholas Ward
ever wanna be the best at any cost? being coy here.
Levi Roberts
If your functions have more than 50 lines, it's time to refactor.
Gabriel Hall
Check Derek Banas tutorials on youtube. What hes doing is basically what every programmer does: adding modularity. Data and function organization in classes.
It becomes simpler to change or reuse some parts of the code.
I know jack shit about code optimization though (compiling and perfomance speeds "oooh da shitty pointers" and "the trenary operator is better/faster/slower than this if else or switch case).
Jose Kelly
Here's why someone would redo it this way:
- the original code is about 300 lines, but was that all the functionality that would be in there? If not, refactoring to the 5 or so classes (Player, Game, Projectile, World, Renderable) could make it easier to add the functionality that is missing and reuse. What if you want the player to do something else, etc? In the original code, would you then add it as another switch statement / if statement deeper in your main method? What's there currently in the original code is already hard to understand -- how much harder to understand will it be once you add something besides just a character moving and jumping with a static background?
- Yeah, it looks a bit overkill for the short program, but if there should be more stuff going on, those classes are encapsulating the different parts of the program from each other. In code for the world, you can't accidentally mess up variables from the player for instance.
- There are twice as many files as classes because C++ has header files. Some other OO languages don't have header files.