[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]

Bad Programming Practics

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: 45
Thread images: 3

File: 1733734.png (139KB, 512x512px) Image search: [Google]
1733734.png
139KB, 512x512px
1) Select a language
2) Post bad practices so we can remind ourselves to stop doing them
>>
File: cumberthis.gif (385KB, 300x177px) Image search: [Google]
cumberthis.gif
385KB, 300x177px
int a;

not int a = 0;

In c always fucking init your frigging variables.
>>
>>55492194
This so much

Don't know why for-loop got cut from the standard either, comfy as fuck for looping
>>
>>55492194
Why would int a; always be a bad idea?

>>55492399
For loops still exist.
https://en.wikipedia.org/wiki/C11_%28C_standard_revision%29
>>
>>55492194
Sometimes you read input into your variables, so it doesn't matter.
>>
Here's a basic one, is x larger than y.

1) Any language
2)
if (x >= y)
return true;
else
return false;
>>
Creating objects or new variables inside a loop over and over instead of defining them outside the loop once.
>>
>>55492552
it's initialized to garbage, whatever value happens to be on the stack at the time. it's a best practice to always set a deterministic value.

if you have good code analysis tools it's not necessary as they will warn you if you attempt to read before setting it.
>>
>>55492756
I don't get it. Why couldn't it just be :

return x >= y;
>>
Using loops when you can use a matrix in Matlab
>>
Setting the return value as a class property and returning null from the method. Specifically PHP but could be a lot.
>>
>>55493091
because faggots can't into if. That faggo is probably a first year CS
>>
writing code in python
>>
writing a UI

>c++
>#include "class.h"
>#include "class.cpp"
>>
>>55493091
>>55495227
>2) Post bad practices so we can remind ourselves to stop doing them
That's the point you idiots
>>
>>55495333
why is that UI specific?
And why bad practice? I always do it (although I never code UIs)
>>
>>55496023
Using c++ is the biggest mistake here.
>>
>>55491155
1) Java
2) using it unironically
>>
>>55496602
What's wrong with C++?
>>
>>55496640
everything, but I'll start:
> cin/cout and related hacks
> OOP language without GC in (current year)
> dozens of different variants of each primitive data type (oh, you want an integer? that's actually called "uint16" in our code!)
> hilarious lack of infix operator defines/overloads
> bad for functional
>>
>>55496695
what a meme post
>>
>>55492552
It's not always a bad idea, but usually unnecessary. Unless you have a specific reason not to, give it a value on declaration.
>>
Using static types.
>>
>>55496880
this, it's 2016
>>
in C++ you don't need to shoehorn in class inheritance where it isn't necessary... and it's almost never necessary
>>
>>55492814
the compiler will actually just fix this for you lol
>>
>>55497139
>compiler optimizing what you don't want it to optimize
>>
>>55497374
Why the fuck does it do it then?
>>
>>55497374
ok autist
>>
>>55497549
If you're telling me your compiler compiles your code so that creating new objects within a loop has the same effect outside, considering every object's constructors may affect something static, then your compiler is shit

>>55497565
How is it autistic?
>>
>>55491155
Python:
def list_square(li):
length = len(li)
for i in range(0, length):
li[i] = li[i] * li[i]
return li
>>
>java
>actually using it
>>
>>55492756
>>55493091
return x >= y; is less legible senpai.

The one thing I wish would be weeded out by a mass genocide is opening the wrapper on the same line as the if/loop statement.
>>
>>55496695
The alternatives are either not OOP, are bloated as fuck, or you use C# and are stuck developing on and for Windows.
>>
>>55500071
also C# is bloated as fuck
>>
>>55496640
People with two-digit IQs don't like it.
>>
>>55492194

This guy is retarded.

Class name{
int a;
name(){
a=1;
}
}

Look, I used int a; and it's completely normal and proper in this context.
>>
File: 1448400541726.png (14KB, 438x499px) Image search: [Google]
1448400541726.png
14KB, 438x499px
>>55500137
>name() {
>>
>>55496640
It's too hard for dumb people.

Remember, we want programming to be an "inclusive" skill!
>>
>>55500137
Nigga it's 2016, use constructor initializations.
>>
>>55491155
Python

Making something that should be a function a class whose constructor returns the object you want.
>>
>>55500137
A class member isn't a variable. And that's not C. That's not even C++.

>>55500515
He said Class, not class.
>>
>>55497571
Uh, you're an idiot. There is no "may"; the compiler knows if your object's constructors affect something static or not.
>>
>not using switches

If (i == 4) return 5;
If (i == 6) return 7;
If (i == 8) return 9;
Etc
Etc
>>
>ruby
Method Overload
module sex
def fuck
...
end
def pussy
...
end
def penis
...
end
end
a.pussy.penis.fuck


Just Don't
Thread posts: 45
Thread images: 3


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