[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Programmers, post your tips for maintaining clean code. For

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 76
Thread images: 5

Programmers, post your tips for maintaining clean code.

For me personally, as a rule of thumb, I aim to have it so the entire code can be understood just by reading a list of bullet points.
>>
I personally use clean VIPMVVMPWTFBBTQ it just works so well :)
>>
indent and space things the same throughout your code, don't have

if(x==1){
}

and

if(x == 1)
{}
>>
>>62432584
What does that stand for?

I know the MVVM part means Model-View-ViewModel, but what about the rest?
>>
>>62432555
Try to put everything on one file
This is the keep it simple(KIS) method
>>
>>62432555
If
(
){

}
>>
This thread proves /g/ don't actually know how to program.
>>
As a professional coder, i always remember to put exactly three spaces in between the argument and function name for every code block because the compiler optimizes for 3 whitespaces ever time
>>
File: 1477883934266m.jpg (66KB, 501x1024px) Image search: [Google]
1477883934266m.jpg
66KB, 501x1024px
>>62432555
>I aim to have it so the entire code can be understood just by reading a list of bullet points.
>>
>>62432752
>WTFBBQ
>>
I usually try to go by the DRY principle. Sometimes it takes more work, but damn it is satisfying when you realize you can just reuse a function or something you made modular.
>>
>>62433861
I don't know what that has to do with the quoted statement, but okay.
>>
>>62433861
>This a function
>This a Engrish
>>
>>62433861
Before I read the commands, I thought it was the *women* they were trying to make fun of there.
>>
>>62433861
cd code
cd
cd
ls
cd ..
cd code
cd
cd
>>
Make sure u wear ur programming socks!
>>
I make all my projects effective and write everything on ONE line
>>
>>62432555
The only tip you need is to not merge pull requests by Pajeets.
>>
>>62433861
Exactly what I want
>>
>>62432555
I try to use as few variables as possible.
And preferably only variables with a clear meaning, not just be counters or intermediate steps.

Assigning the values in one step can be a little complex.
But in the larger scope it's much clearer what is going on.
>>
>>62435060
i do the same because i hate variables of short lifetime, when i can do anonymously, i do
>>
- don't use else
- quick return
>>
1 Descriptive names for all classes, members, and variables
2 Short functions
3 One class per file
4 Good folder organization
5 Lots of private properties on the class to help optimizing function size, leading to well conceived objects and promoting purpose and abstraction
>>
>>62432555
Don't let anyone else contribute to it
>>
every two years I delete it and start again
>>
>>62435380
unironically this
>>
I only pass parameters in the constructor if either the data is a fundamental part of the object, or the object exists solely to work with said data. For anything else, I use initialiser syntax or whatever method is most appropriate for the situation.
>>
If possible, I always try to stamp out any possible "wrong" way of doing something.
>>
>>62433575
B-But anon, I can fizzbuzz! O//w//O
>>
I start with a simple structure and then shit on it untill it needs to be rewritten.
>>
>>62435722
This. Also change variable names at random points
>>
>>62435722
Same!
>>
>>62432555
http://mindprod.com/jgloss/unmain.html
I follow thse guidelines religiously
>>
File: 1500177885986.jpg (3MB, 3200x4212px) Image search: [Google]
1500177885986.jpg
3MB, 3200x4212px
Try to make code as small as possible.
Least amount of boilerplate like functions, classes etc.
Smallest possible names for variables, functions etc.
Be expressive with your code, write one-liners that capture as much behavior as possible.
Keep it small, you will thank me later when you have to go look your own code. Having it be small is a huge time saver.
>>
>>62432555
import Data.Functor.Foldable

Can't make it cleaner than that though it sets the entry bar a bit high for the next guy
>>
>>62432555
If I can't follow it using my development environment, it's poorly designed.
Functions should fit on the screen (NASA standard is it can be printed on a single sheet)
If the language has a lot of very fancy features that aren't quickly picked up by a beginner, don't use them unless you absolutely need to (macros in clojure for example).
Long variable names generally. This is the 21st century, we have autocomplete
>>
>>62432555
Intelligent software architecture.
Good documentation (e.g. XML doc in C#).
Clear commenting throughout the code.
>>
>>62432555
Unless you live in third world country your only job should be producing UML-diagrams which you email to the outsourcing company. Writing code yourself is lowly pajeet job for the feeble minded.
>>
>>62432555
Clean code is for virgins. I do the Chad programming: write unstable code in multiple languages, chain them awkwardly together, and use brute force power to increase the speed of the program instead of optimization
>>
>>62436082
just use recursion-schemes, nobody will understand it but it will be fast
>>
>>62432593
astyle helps a lot with this.
>>
>>62435975
>If the language has a lot of very fancy features that aren't quickly picked up by a beginner, don't use them unless you absolutely need to (macros in clojure for example).
In my experience, this yields the exact opposite of what you want. Foregoing complex features at the cost of repeating yourself or making your abstractions less accurate is usually a net loss.

Restricting yourself to simple language structures is a good way to keep your code accessible to beginners, but generally prevents it from becoming effective for wizards to work on.
>>
File: smug.jpg (2MB, 4940x3740px) Image search: [Google]
smug.jpg
2MB, 4940x3740px
>>62435938
> use a minifier for my script
> the file is actually longer
>>
>>62432555
Do as much design work as you can before you write anything, its helped a few times turning what would have been 50 lines into 20.
>>
>>62432555
Make as many things state machines as possible. Makes it really easy to test too.
>>
>>62432555
I use obscure variable and function name that in no way elude to the actual function or variable behavior. This is a psychological trick, it forces you to commit them to long term memory
>>
>>62432555
Build no side effect methods, build public data type, private date types, side effect methods(thread,IO,Network,UI) begin well isolation. Use code as draft program each couple weeks refactory.
>>
>>62432593
or in simpler terms, be consistent.
>>
I try to avoid using "else if" as much as I can, because why not just use a switch?
>>
>>62436716
>why not just use a switch?
Because switches limit the ability to expand code. Use objects instead.
>>
>>62436798
Oh yeah, good point.
>>
>>62432555
Why on earth would I want to do that? My code is an unreadable mess and I like it that way. Gives me job security. Nobody else is willing to touch my shit with a ten foot pole, because they know they'll break something.
>>
>>62435975
Reminds me of how much I love this one ~3.5k line function at work.
>>
>>62432555
I like to make things complicated desu. So I do the opposite, variables in multiple languages that I speak, leverage other languages within, ofc utilize meta programming for everything. I also use a different language for each project for fun. I get bored easily and programming is too easy desu.
>>
>>62436053
I'd rather be pajeet slaving away at the code face a kilometre underground for whatever rupee cents are than ever have to touch UML again.
>>
>>62433861
>if
>else if
>else
>"this is why more women should be programmers xd"
YAMERO
>>
Consistent bracing, not declaring variables until they are used, tabs (4 space width), never more than 4 levels of indentation, 80 column text, concise comments only where necessary.
>>
keep your main method as minimum as possible
>>
>>62432555
I recommend the cleancoders video series.
Basically you have to refactor your codebase until it is not a well written prose.
>>
>>62433861
>returns five because I'm so random
The fuck?
>>
>>62435938
womanlet
>>
File: random_number.png (7KB, 400x144px) Image search: [Google]
random_number.png
7KB, 400x144px
>>62438958
Probably a typo
>>
>>62432555
Make sure to write recursive functions that call each other.
>>
>>62433140
ew
>>
>>62434916
Are you trying to hack me?
>>
Follow coding conventions, comment on important things and most important of all: be consistent.
>>
>>62433861

S H A L O M
H
A
L
O
M
>>
>>62432555

> 1. Make you data structures immutable.
> 2. Release resources as close to where you open them
> 3. Write tests, you don't know who will maintain the code later.
> 4. Code comments describe "why", not "what".
> 5. Don't use variable names like "tmp" or "z".
> 6. Break lines at highest semantic level. Group syntax tokens visusally.
> 7. Reduce visibility, make classes final.
> 8. Don't optimize code until you have profiled it.
> 9. Never skip profiling your code.
> 10. Don't use float or double when an int will work.
>>
>>62432555
Comment and make sure they're clear and easy to follow.
>>
>>62433861
>int function
// returns an int ;D
// an int is a number without decimal
// ^_^

Holy shit what the fuck, I'd fire that bitch immediately. Wasting more time and space stating the obvious than doing anything. Fuckfuckfuck, I'm triggered.
>>
>>62433937
it's a good rule of thumb but some people really overdo it and end up with leaky abstractions
>>
>>62439355
This guy knows what's up
>>
>>62433861
>It is hacker code used to steal nude photos!
keked
>>
>>62439355
this
>>
Api first
>>
>>62437097
what's it do?
Thread posts: 76
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.