Programmers, post your tips for maintaining clean code

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.

Other urls found in this thread:

mindprod.com/jgloss/unmain.html
twitter.com/NSFWRedditGif

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)
{}

What does that stand for?

I know the MVVM part means Model-View-ViewModel, but what about the rest?

Try to put everything on one file
This is the keep it simple(KIS) method

If
(
){

}

This thread proves Sup Forums 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

>I aim to have it so the entire code can be understood just by reading a list of bullet points.

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

I don't know what that has to do with the quoted statement, but okay.

>This a function
>This a Engrish

Before I read the commands, I thought it was the *women* they were trying to make fun of there.

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

The only tip you need is to not merge pull requests by Pajeets.

Exactly what I want

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.

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

Don't let anyone else contribute to it

every two years I delete it and start again

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.

B-But user, I can fizzbuzz! O//w//O

I start with a simple structure and then shit on it untill it needs to be rewritten.

This. Also change variable names at random points

Same!

mindprod.com/jgloss/unmain.html
I follow thse guidelines religiously

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.

import Data.Functor.Foldable
Can't make it cleaner than that though it sets the entry bar a bit high for the next guy

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

Intelligent software architecture.
Good documentation (e.g. XML doc in C#).
Clear commenting throughout the code.

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.

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

just use recursion-schemes, nobody will understand it but it will be fast

astyle helps a lot with this.

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

> use a minifier for my script
> the file is actually longer

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.

Make as many things state machines as possible. Makes it really easy to test too.

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

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.

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?

>why not just use a switch?
Because switches limit the ability to expand code. Use objects instead.

Oh yeah, good point.

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.

Reminds me of how much I love this one ~3.5k line function at work.

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.

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.

>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

I recommend the cleancoders video series.
Basically you have to refactor your codebase until it is not a well written prose.

>returns five because I'm so random
The fuck?

womanlet

Probably a typo

Make sure to write recursive functions that call each other.

ew

Are you trying to hack me?

Follow coding conventions, comment on important things and most important of all: be consistent.

S H A L O M
H
A
L
O
M

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

Comment and make sure they're clear and easy to follow.

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

it's a good rule of thumb but some people really overdo it and end up with leaky abstractions

This guy knows what's up

>It is hacker code used to steal nude photos!
keked

this

Api first

what's it do?