Jump to content

Could we make a thread specifically about bad practices?

darth_bubbles

using public variables in a class

 

always use accessors/mutators 

i7 3770 | Asus Z77 Pro | 16gb Kingston HyperX 1600 | Corsair AX750w | Steelseries 6Gv2 + Logitech G502


GPU: Asus R9 280x Direct CUII (complete with the famous VRAM issues/artifacts feature enabled)


stuck in elo hell, chillen with morello

Link to comment
Share on other sites

Link to post
Share on other sites

#define struct union

main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}

Link to comment
Share on other sites

Link to post
Share on other sites

Using

break;

is a bad practice....or so every professor i've had likes to say--although It certainly has its merits. 

Definitely not so. In a switch or loop statement this can cut down on wasted CPU cycles.

Link to comment
Share on other sites

Link to post
Share on other sites

Definitely not so. In a switch or loop statement this can cut down on wasted CPU cycles.

It has its uses, but it's generally considered bad style, and can often be easily avoided. 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

using public variables in a class

 

always use accessors/mutators 

A lot of IDE's can even autogenerate them for you...

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

A lot of IDE's can even autogenerate them for you...

that in itself is also kind of a bad practice

 

code generated by IDE's is something to be careful of, especially for learners who end up taking it for granted and don't fully understand their purpose

i7 3770 | Asus Z77 Pro | 16gb Kingston HyperX 1600 | Corsair AX750w | Steelseries 6Gv2 + Logitech G502


GPU: Asus R9 280x Direct CUII (complete with the famous VRAM issues/artifacts feature enabled)


stuck in elo hell, chillen with morello

Link to comment
Share on other sites

Link to post
Share on other sites

that in itself is also kind of a bad practice

 

code generated by IDE's is something to be careful of, especially for learners who end up taking it for granted and don't fully understand their purpose

Always check it yourself (and almost always you have to make some ajustments) but I don't think it is a bad practice per se.

private int number;public int getNumber(){        return number;}

There is not very much that can go wrong in cases like this but it saves you another 5 minutes if you have a couple of variables. I'm not talking about things like toString or "even" more complex methods/functions.

Build log "Whiplash" : http://linustechtips.com/main/topic/158477-the-hero/

Whiplash: 4790k@4,4Ghz|Maximus VII Hero|4x4Gb Red/Black HyperX fury 1866Mhz|R9 290 Tri-X|Modded 450D|Sleeved cables on a M12II evo 850W|M500 480Gb| BenQ XL2411T@144Hz

Laptop: 4700MQ|16Gb@1600Mhz|Quadro 1100M|1080P|128Gb SSD|500Gb 7200RPM hdd

Link to comment
Share on other sites

Link to post
Share on other sites

It has its uses, but it's generally considered bad style, and can often be easily avoided. 

Indeed there are better ways of doing it rather than using a break after every case statement. As it would generate a lot of extra lines of code that are not needed.

Link to comment
Share on other sites

Link to post
Share on other sites

Always check it yourself (and almost always you have to make some ajustments) but I don't think it is a bad practice per se.

private int number;public int getNumber(){        return number;}

There is not very much that can go wrong in cases like this but it saves you another 5 minutes if you have a couple of variables. I'm not talking about things like toString or "even" more complex methods/functions.

I'm talking about why getters/setters are used, and why you should create proper class interfaces and not just let classes access variables directly, people dont realise the importance of encapsulation, etc early on and they create bad habbits 

i7 3770 | Asus Z77 Pro | 16gb Kingston HyperX 1600 | Corsair AX750w | Steelseries 6Gv2 + Logitech G502


GPU: Asus R9 280x Direct CUII (complete with the famous VRAM issues/artifacts feature enabled)


stuck in elo hell, chillen with morello

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×