[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Bad Programming Practics
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 45
Thread images: 3
File: 1733734.png (139 KB, 512x512) Image search: [Google]
1733734.png
139 KB, 512x512
1) Select a language
2) Post bad practices so we can remind ourselves to stop doing them
>>
File: cumberthis.gif (385 KB, 300x177) Image search: [Google]
cumberthis.gif
385 KB, 300x177
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 (14 KB, 438x499) Image search: [Google]
1448400541726.png
14 KB, 438x499
>>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 replies: 45
Thread images: 3

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.