Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Retarded Coding Standards

Name: Anonymous 2012-06-22 1:20

"Always compare equality with a constant on the left, for example if (5 == maxUsers) instead of if (maxUsers == 5). If neither of the expressions being compared are constants, rewrite the condition so it is, for example if (0 == userCount - userLimit) instead of if (userCount == userLimit)."

"For consistency with the previous rule, non-equality comparisons should also be formatted using the same style. For example, use if (0 < userCount) instead of if (userCount > 0), and if (0 < userCount - userLimit) instead of if (userCount > userLimit)."

Name: Anonymous 2012-06-22 1:28

What software are those coding standards used for so I can laugh at it?

Name: Anonymous 2012-06-22 1:30

Okay, now I'm curious. What's the source of this? I mean are there some arguments pro/con to this?

Name: Anonymous 2012-06-22 1:41

>>3

It's called yoda conditions. It's a defensive programming technique to protect from accidental assignment -- since = is close to ==.

I don't see any purpose for it. I've never had accidental assignment before.

Name: Anonymous 2012-06-22 2:17

I don't think the tradeoff is worth it at all. if (0 < userCount - userLimit) is much less readable than [code]if (userCount > userLimit)[code].

Name: Anonymous 2012-06-22 2:18

I don't think the tradeoff is worth it at all. if (0 < userCount - userLimit) is much less readable than if (userCount > userLimit).

Now could someone please design a defensive technique to protect from forgetting to close your BBCode tags?

Name: Anonymous 2012-06-22 2:22

So that's considered retarded? How retarded are you to find it retarded?

Name: Anonymous 2012-06-22 2:38

>>7
It is retarded. Reading code with yoda conditionals is like trying to read a novel in which the author consistently uses a verb-object-subject structure.

Name: Anonymous 2012-06-22 3:03

>>7
How retarded are you to find him retarded because he finds it retarded?

Name: Anonymous 2012-06-22 3:58

I don't see the point of this. How could someone mistake setf for eq or another equality function?

Name: Anonymous 2012-06-22 5:34

>>10
smug lisp asshole.

Name: Anonymous 2012-06-22 5:52

Is there no compiler switch that warns when code like if (a = b) shows up?

Name: Anonymous 2012-06-22 5:55

>>12
GCC does this.

Name: Anonymous 2012-06-22 5:55

>>12
$ cat foo.c
int main()
{
    int x = 0;
    if (x = 1) {}
    return 0;
}
$ gcc -Wall -Wextra foo.c
foo.c: In function ‘main’:
foo.c:4:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]

Name: Anonymous 2012-06-22 6:07

>>13
>>14
Well then Yoda conditions proven for retarded bullshit.

Name: Anonymous 2012-06-22 6:10

>>15
>>13
>>14
Please optimise you are quote references.

Name: Anonymous 2012-06-22 6:14

>>16
Thats how I like my /prog/.

Lets see how this works..
>>13,14
>>13-14
>>13..14

Name: Anonymous 2012-06-22 7:19

//...
            int x = 7;
            if (x = 8) {
            }
 //...


Retarded.cs(15,8): error CS0029: Cannot implicitly convert type 'int' to 'bool'

Name: Anonymous 2012-06-22 7:58

That is a different type of error, try

bool x = true;
if(x = false)


and report back

Name: Anonymous 2012-06-22 8:28

>>19
That should still fail in C# because 'x = false' is not an expression.

And, lo and behold, with Mono (gmcs), this code:
using System;

namespace Scalable.Enterprise {
    class Module {
        public static void Main(string[] args)
        {
            bool ScalableEnterpriseBoolean = true;
            if (ScalableEnterpriseBoolean = false)
                Console.WriteLine("``faggot''");
        }
    }
}

gives these warnings:
gmcs -out:ScalableEnterpriseModule.exe ScalableEnterpriseModule.cs
ScalableEnterpriseModule.cs(8,55): warning CS0665: Assignment in conditional expression is always constant. Did you mean to use `==' instead ?
ScalableEnterpriseModule.cs(7,30): warning CS0219: The variable `ScalableEnterpriseBoolean' is assigned but its value is never used
Compilation succeeded - 2 warning(s)

Name: Anonymous 2012-06-22 8:32

>>18
That's SEPPLES

Name: Anonymous 2012-06-22 10:40

>>20
because 'x = false' is not an expression.
Incorrect. Assignments are expressions. You probably don't even understand the warnings.
back to >>>/g/

Name: Anonymous 2012-06-22 11:31

I had sex a couple of days ago, with a girl.

Name: Anonymous 2012-06-22 11:38

>>23
i had sex two hours ago. she haxed my anus.

Name: Anonymous 2012-06-22 11:41

>>24
Joke is on you, we are having trouble in our relationship.

Name: VIPPER 2012-06-22 11:53

>>25
Still better than trouble in your anus.

Name: Anonymous 2012-06-22 15:07

Okay, well what if userCount or userLimit aren't integers, but Strings, or Arrays, or Structs? What if userCount - userLimit doesn't actually make sense because the method - isn't defined for userCount?

Better solution for Object Oriented Programmers:

if userCount.eql? userLimit

Or for functional programmers:

(eql? userCount userLimit)

Name: Anonymous 2012-06-22 15:37

>>27
Best solution for everyone:

//;--# Disclaimer: the syntax here is completely arbitrary, I'll use all comment syntaxes I know to achieve full neutrality, except VB's because it's retarded above salvation.

--//#; `let', `var', whatever to declare variables, refs instead of everything-is-mutable (optional).
let x = getX(), y = make_ref(2);
//--#; (:=) assigns to refs/mutable variables. Its return type is void or unit.
y := 3;

#//;-- Then equality is one of:

;#//-- If the language doesn't permit definition of new operators. If it's in a let, it's a binding =, else it's just an operator.
if x = y ...
#;--// the usual, x = y is a syntax error: expected expression, got a binding form.
if x == y ...

Name: Anonymous 2012-06-22 15:40

>>28
Disregard the first part of the second to last comment, I just realized Haskell does the same with (.) and modules.

Name: Anonymous 2012-06-22 16:29

GNU coding style is retarded. And GNU software's quality is a consequence of the former.

Name: Anonymous 2012-06-22 17:27

>>30
lel

Name: Anonymous 2012-06-22 19:38

Protip:

If you can remember to use yoda conditions, you'll also remember to use '==' instead of '='.   If you forget to use '==' instead of '=', you'll also forget to use yoda conditions.

Making the rule worthless. QED

Name: Anonymous 2012-06-22 19:47

>>32
stop having common sense, it's offensive to feminists.

Name: Anonymous 2012-06-22 21:57

>>14
That warning needs to be made narrower, since

while(c = ...) { /* do something with c */ }

is a common idiom for processing null-terminated strings (or other things that end when they're zero). I'd suggest making it warn only if you're assign a constant or single variable, like

while(c = 5)

because that's something almost never encountered in practice. while(c = <some complex expression that returns 0 when it's time to exit the loop>) is a lot more common.

Name: Anonymous 2012-06-22 23:38

>>34
The warning is fine. It's just a warning, and if you want to avoid it, you can write while ((c = ...)) instead to indicate you're absolutely sure you know what you're doing.

Name: Anonymous 2012-06-23 7:51

    >and if (0 < userCount - userLimit) instead of if (userCount > userLimit)."
Retarded

Name: Anonymous 2012-06-23 8:43

Yoda Conditions is Hungarian Notation for conditional logic.

Name: Anonymous 2012-06-23 16:38

If C used := for assignment and = for equality like Pascal and Algol, there wouldn't be this problem in the first place.

Name: Anonymous 2012-06-23 17:04

>>38

#define := =
#define = ==


lel ecksdee

Name: Anonymous 2012-06-25 12:13

㒒♩ᢀ刐▖ၓ荈ቢㄸ᤹⠗腦䔢ᖒ塵Ŷ颐䝳⢁儨蝐䜥㘀䠁ᝃ灩砢奤̤堇䑈䤓蜗硷ᔵܦ❱ᖀᎉY፸搖舢䘖䠤爔7卄⢂憀昨㙕㑩԰呣嘖饨ࡹ⥨ц⡀关⎙❗㡹肗抐啕Ėᔕ隕頦ဠ芑剴鐓覐㙰Х琠蘲蜣戓䘙㍥塐ᖕ䖅摈畓恓螄茄က琩㝀饴䕡撐锸虄睸₃褧䉰榖爑䑲啂⠘㍰硦গ耗ጸ栦ᑇ昷瑣䐱朱钖ᜉ妀蒈獄䥙炓͕鑹蕄і㙔⤀ㄔၥ瘲䈐䐑ₑ頳㕴∗厔妇♦䤂喗薉ሗ儤⠣⑘卒掇睰ቀ၄省咄┡䦔猁冁攃ᘀ荳塥Xᝩ醙噲閈Β晷恒閄栄焧㉦怆䕵蜣頥冖榉ᑸ⌱鉠猱㉹鐲偈蝁䑄剅耦ᥒ靖ゕاܓ┄颗ᡉ唂gᒀ爐馂ቇㅳℳᠤ癑遘恒Ė顂憄唗妘鈆㙂著耢ဦ㙈慇厔Гᐢ兂逡蝙㑀挑偄灐ı聧ᅣᢈᜃ⠣䅠㘐䝈戀聳脧瞐ق㔲䒖㉈㜅慒≂础餄顐肙褂ո⁩杢喙Ņ㠵刵艔袁蒈匸瀴᝖䡠坨嚈榆虢‚㡵萢Ʉ蚄瑅䙸䅩向喓ᦖ‰犙ٖ䂅灦ጥ搒

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List