[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
camelCase or under_score?
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: 149
Thread images: 9
File: IMG_20151229_105644_5161.jpg (177 KB, 1437x699) Image search: [Google]
IMG_20151229_105644_5161.jpg
177 KB, 1437x699
camelCase or under_score?
>>
File: ij.png (3 MB, 1280x720) Image search: [Google]
ij.png
3 MB, 1280x720
Both
>>
depends on the language.
For SQL tables I prefer underscores.
In C# pascal- and camelcase, and in javascript camelCase.
>>
>>52119605
Obfuscuregret
int juliewhy = 3;
int juliewhydidyouleavemejulie = 4;
struct icantfuckingstopcryingwhy
{
int JULIEINEEDYOU = 1;
}
>>
>>52119605
ofc underscore camel case looks fucking retarded, who invented this shit?
>>
>>52119605
variables: camelCase
defines, constants and similar: ALL_CAPS_UNDERSCORE
>>
File: 1419986315049.jpg (28 KB, 600x600) Image search: [Google]
1419986315049.jpg
28 KB, 600x600
>>52119647
Good taste.
>>
Both for different usages. e.g. functions and variable names Camelcase and html files under score
>>
Both depending on the usage.

Also, prefixing number is retarded. 3.073685 is a number

intCats or iCats is the only acceptable format.
>>
>>52119706
>iCats
Apple plz go
>>
>>52119654
that's not taste, that's basics of 'spelling' in programming.
>>
Underscore is for savages, healthy, successful people use camel case.
>>
>>52119638
ouch
>>
under score is much more readable and in my default choice language - python
its the recommended style

unfortunetly we are tiny minority
camelCase is far far more popular
>>
File: youAreRetarded.png (57 KB, 202x200) Image search: [Google]
youAreRetarded.png
57 KB, 202x200
camelCase

For membervariables I use
_camelCase

Everything else is retarded
If you write
m_camelCase you are retarded. If you don't like my opinion you are retarded. If you like it, but think I'm stupid, you are retarded.
>>
>>52119706
>unironically using hungarian notation

>>52119605
numberOfCats (or catsCount if you prefer shorter names)
>>
>>52119605
camel toe
>>
heres how master race do it
int my_variable
class MyClass
{
int_my_member_
}
int MY_CONST_VAR
>>
>>52119643
>ofc underscore camel case looks fucking retarded, who invented this shit?

this
>>
>>52119796
>For membervariables I use
>_camelCase
if you need a prefix to tell you something is a member, your methods are too long.
>>
>>52119750
>Underscore is for savages, healthy, successful people use camel case.

That's why I'm always using underscore. It's my way to tell you: suck_muh_dick_normie. And it its more readable too.
>>
so underscore can be easier read at a glance, but camel case uses less memory?

inb4 negligable
>>
>>52119815

Also this
>>
public class MyClass 
{
private _privateProperty;
public int PropertyName { get; set; }

public void MethodName(int parameterNumberOne, float parameterNumberTwo)
{
. . .
}
}
>>
>>52119815
https://www.youtube.com/watch?v=0hiUuL5uTKc&t=7
>>
if it's my project I use underscores
if it's not then follow whatever the rest of the codebase uses
>>
Underscores are ass, use hyphens:
(setf number-cats 5)
>>
>>52120005

bool hyphens-Camel-Case-Master-Race-Reporting-In-For-Duty-And-The-Win = true; 


>Simple
>Readable
>Brilliant
>>
>>52119923
> more readable
You must be a beginner then (^:
https://whathecode.wordpress.com/2011/02/10/camelcase-vs-underscores-scientific-showdown/

> Camel casing has a larger probability of correctness than underscores. (odds are 51.5% higher)
> Those with more training were quicker on identifiers in the camel case style.
>>
>NUMBERcATS
anyone else?
>>
>>52119605
consistency, that's what matters
>>
>>52119647
what about functions?
>>
File: 1450073458762.gif (2 MB, 500x282) Image search: [Google]
1450073458762.gif
2 MB, 500x282
>>52119647
Best taste
>>
>>52121122
>variable
what are you on about anon
>>
File: attachment.png (378 KB, 1379x844) Image search: [Google]
attachment.png
378 KB, 1379x844
Step aside plebeians. Visual Scripting master-race reporting in. Our variable names can have capitalization, spaces- whatever you want.
>>
"number" can be used as a verb. Better to use "cat_count" or "catCount".


I prefer this_because thisIsImpossibleToReadAndDoesntWorkForAcronymsFactory
>>
>>52121227
I bet you really liked Minority Report when you were a teenager. You'll never be John Anderton.
>>
>>52119605
java, c# - numberCats
python - number_cats

There is such a thing as coding standards, stop getting these autists arguing
>>
>>52121295
obviously there are standards, and you should stick to them. the argument is which one you think is better.
>>
>>52119815
this
>>
File: maria_>:3.png (501 KB, 537x544) Image search: [Google]
maria_>:3.png
501 KB, 537x544
>>52121072
This guy right here.

Visually, underscores are more readable for me, but that is just preference I guess
>>
>>52121227

> and this is a function that prints to stdout.
>>
>>52119803
>numberOfCats (or catsCount if you prefer shorter names)
This. What the fuck is a number cat and why is it 5?
>>
>>52119647
I do the same, the best imo.
>>
>>52119605
Either, dependent on your language's style guide
>>
>>52119803
>numberOfCats
Holy fucking shit you fat american piece of shit kill yourself
First the wider category then the sub category or attribute.
cats-count
>>
>>52119803
> Not using catscnt
>>
>>52121672
>I can't even finish reading the post
>>
>>52121672
>First the wider category then the sub category or attribute.
oh you mean like MM-DD
>>
>>52119605
>claims to be a programmer
>takes photos of screen
>>
>>52121295
this. especially if you use a babby language like java, you can have real issues with some libraries if you don't follow the standards.
>>
File: rms.png (26 KB, 614x130) Image search: [Google]
rms.png
26 KB, 614x130
>>52121739
>>
>>52119827
you are retarded. he warned you.
>>
>>52119605
Underscores are more readable and make refactoring names easier. Literally the only argument for camelcase is "but it's too hard to write an underscore", which is retarded and only argued by underage retards who don't know how to touch type.
>>
>>52119796
>memevariables
>>
under_score
>>
>>52119796
Don't like it AND I think you're stupid.
>>
kebab-case



#run the same code for different values of the variable
my $number-of-seats = 9;

if $number-of-seats <= 5 {
say 'I am a sedan'
} elsif $number-of-seats <= 7 {
say 'I am 7 seater'
} else {
say 'I am a van'
}


>>
>>52121004
>You must be a beginner then (^:

no just artist.
>>
>>52119631
this
>>
>>52119605
under_score always.
camelCase is the sign of someone who's just started programming.
>>
>>52119706
>>52119738
>>52119803
interface iConvert.toString {
string toString();
}
>>
>>52121794

rsm is a relic
>>
>>52122180
>no just artist.

*autist

Daily reminder that if you're using camel case you're discriminating people with Autism/ADD/Dyslexia and shit...

Don't be bully USE UNDERSCORE!
>>
>>52119605
basically this guy >>52119647
but functions-are-dashed-and-lowercase
>>
>>52119605
I use the language convention. It's not me who chose.
>>
>>52122292
Either you're writing lisp and everything is dashed-and-lowercase or you're retarded if you're mixing three completely different styles.
>>
>>52122200
>camelCase is the sign of someone who's just started programming.

Even worse. All the hipster faggots and JS "web" artisans are using CC. Literally subhumans.
>>
It's called snake case you fucking casuals.
>>
>>52119605
Depends on the language. If the default libraries use camelCase then use camelCase and so on for snake_case.
>>
>>52122108
>mfw I am 7 seater with 6 seats
>mfw I have no face
>>
I do whatever the fuck I want

I use camecase for functions
snake case for variables

def triggerNuke():
...

nuke_codes = [a, b, c, d]

>>
why wouldn't you just use something like ncats, it's easy to read and context makes its meaning clear. As long as you are idiomatic you can shorten a lot of obnoxiously long variable names

I find camelCase unFuckingReadable though, so underscore is preferable when you need longer names
>>
>>52119605
Depends on whether I'm writing Haskell or not.
>>
>variables
anyways, all my functions are camelCase if they aren't just a single lowercase word
>>
>assembly
underscore
>C/C++
pascal case
>OOP languages
camel case
>>
>>52119605
Why would you need two words in your variable/function? If it's a subset of something else it should be in an object with related variables
>>
>>52122357
im writing in a lisp
>>
>>52119647
ive always thought it's the standard...
>>
>>52119605
Depends on the language I'm using. Typically I use camel case in C/C++ and under score in Python.
>>
>>52122808
If all your functions and variables are one word, you're doing it wrong.
>>
>>52119605
why_Not_Both
>>
>not writing everything in CAPS
>>
>>52124742
>NOT WRITING EVERYTHING IN CAPS
>>
>>52119605
underscore for readability
>>
Classnames, variables, properties, methods, and functions: camelCase

Constants: kThingThatWontChange


Underscores bug me because they're easily mistaken for spaces when quickly scanning. Prepending constants with a "k" both makes them identifiable as such and makes autocomplete cleaner and faster.
>>
>>52119605
functions/methods:
public function doSomething($someArgument, $someOtherArgument)
{
// code
}

function doSomething(someArgument, someOtherArgument)
-- code
end
[/ccode]
public void doSomething(type someArgument, otherType someOtherArgument)
{
// code
}


variables:
$numCats = 2;
$isDead = false;
$age = 12;
$name = 'something';

local numCats = 2;
local isDead = false;
local age = 12;
local name = "something";

public int numCats = 2;
public boolean isDead = false;
public int age = 12;
public String name = "something;


defines, constants and stuff like that:
define('SOME_CONSTANT', 'some value');

SOME_CONSTANT = "some value";

public static final String SOME_CONSTANT = "some value";
>>
>>52125434
well i fucked up one tag.

public function doSomething($someArgument, $someOtherArgument)
{
// code
}

function doSomething(someArgument, someOtherArgument)
-- code
end

public void doSomething(type someArgument, otherType someOtherArgument)
{
// code
}

$numCats = 2;
$isDead = false;
$age = 12;
$name = 'something';

local numCats = 2;
local isDead = false;
local age = 12;
local name = "something";

public int numCats = 2;
public boolean isDead = false;
public int age = 12;
public String name = "something;

define('SOME_CONSTANT', 'some value');

SOME_CONSTANT = "some value";

public static final String SOME_CONSTANT = "some value";
>>
I have my own style

 int miaw = 'A' - 60 ; 
>>
>>52119618
NEVER GO FULL RETARD
>tripfag
>weeb
Nevermind, too late.
>>
Pretty much >>52119647 but with:
functions: CamelCase with first letter uppercase
>>
>>52119647
SCREAMING_SNAKE_CASE
>>
>>52126452
sCREAMING_cAMEL_sNAKE_cASE
>>
>>52126887
PUBLIC FUNCLASS dO_sOMETHING($sOME_aRGUMENT, $sOME_oTHER_aRGUMENT)
{
LOCAL nUM_cATS = 2.5;
LOCAL isDead = false;
LOCAL age = potato;
LOCAL name = "it hurts to live";
// kill me pls.
}
>>
int Number_Of_Cats;
Number_Of_Cats = 5;
>>
>>52122292
>>52122357
lisp is the best
>>
>>52124742
>not writing EVERYTHING in caps
>>
int camelCase = 0;
#define UPPER_CASE_UNDER_SCORE 0
void methodCamelCase();
static void method_lower_under_score();
class CamelCase{}
filelowercase.h
>>
>>52124742
>>52127130
>>52127130
YOU MAY ALSO BE INTERESTED IN: http://BASIC-CONVERTER.ORG/
>>
int number of c
>>
>>52127270
OK, 4chan can't handle it, except for the
>>
>>52127295
interesting find
>>
I've been programming daily for the last 9 years and I have definitely thought and read about coding styles before, I'm even using a consistent one, but I've never seen the camelCase vs under_score argument before.

camelCase were just the natural thing when I first started coding. I knew I couldn't use spaces, but I needed to separate the words somehow, so I used upperCase letters, under_score just didn't seemed right in variable names and such. But somehow that's the only way I can imagine constants and defines, huh...

I guess that's just what I saw more frequently in other people's codes.
>>
>>52126989
I hope your computer catches fire and burns down everything you love
>>
>>52119605
>computer scientists: concerned with type systems, side effects, paradigms, etc

>programmers: concerned with available library bindings, performance, and platform support

>bosses of programmers: concerned with the language being object oriented in a way that keeps their hordes of inexperienced employees from stepping on each other's toes too much

>/g/: concerned with aesthetic issues like brackets and indentation styles


Bikeshedding is the proper word for it. /g/ mainly talks about brackets, syntax, and identation styles because it's non complex and everyone can contribute a opinion and be semi valid.

Any real issues will cause too much risk of being pointed out as incorrect or stupid if they're wrong / mistaken.
>>
>>52127836
>>/g/: concerned with aesthetic issues like brackets and indentation styles
The best the dev is, the best he knows why it really matters.
>>
>>52121227
what does this do?
>>
>>52127885
it matters because it doesn't matter?

it's like CompTIA568A vs CompTIA568B. that's as complex as this issue is.
>>
>>52127885
What really matters is e-peen contests. "I can argue better than you can".
>>
>>52119815
>not using define for constants

Pleb
>>
>>52127915
No it matters because it improves readability and maintenance.
>>
>>52119647
This. Functions are camel case too.
>>
>>52127958
Neither way is more readable or maintainable than the other. Prove me wrong.
>>
>>52127958
god damn, you're a fucking retard
>>
>>52127991
Inconsistent indentation is unreadable. Too many stupid blank lines, reduce the quantity of code I can see at the same time. Incorrect spacing rules (like
[f( adjhdfjk)
), is like inconsistent indentation, it's just a fucking mess.
>>
>>52127958
says the "programmer" over here.

get a load of this guy.jpg
>>
>>52119605
What you mean is snake case.
>>
>>52128017
Inconsistent styles are not so maintainable. That's why you adhere to a style guide for most purposes and break it you understand the rules.
>>
>>52127836
Truer words were never spoken on /g/ before except that OP is a faggot. I wonder why do I even visit this website anymore.
>>
>>52119605
on python, my own standard:

AAA_AAA = global variables

aaa_aaa = functions, variables, methods and attributes

how do i differentiate, i choose cognitive names
( work = function,
self.work = method,
worker = variable,
self.worker = attribute.)

i also comment too much my __init__ attributes setup.

(i normally don't explain too much:
cat = variable
action_cat = function for cat
cats = list of cat)

AaaAaa = classes

aaaAaa = i don't use.
>>
>>52119605
neither.
using a shift key unless i need >, |, (, ), {, }, ", :, or > is a waste of valuable time.
>>
>>52119937
Memory is cheap, fag.
>>
Whatever is convention for the language, project or company/organisation.
>>
>>52119937
If your language occupies extra memory because of underscores, it's a shit language.

If you're concerned about the maybe 2% increase in filesize due to added underscores, you need to just get the fuck out already.
>>
>>52119605
under score because it looks slick as shit
>>
>>52124742
>not writing everything in lowercase
>>
CamelCase. Because it reduces file size.
>>
>>52128726
Like that, with upper case at the beginning?
>>
>>52128777
No, I was capitalizing the first letter of my sentence.
>>
>>52121794
What does he even do on his computer any more.
What does he make in his spare time?
>>
>>52128793
fair enough
>>
3-IUsewhateverthe.fuckIwant!! in Lisp
>>
>>52119605
>naming your variables
wew top lel
if you were a real programmer you would just name everything ililililili or similar.
>>
>>52126381
No
>>
>>52128876
#include <stdio.h>
char* IlI[] = {"fizz\n","buzz\n","fizzbuzz\n","%d\n"};
int lIl;
int Ill (int IIl) {
if (IIl % 15 == 0)
return 2;
if (lIl % 3 == 0)
return 0;
else if (IIl % 5 == 0)
{
return 1;
}
else return 3;
}
int main (int III, char** lll) {
III =0;
for (lIl = 1; lIl <= 100; lIl++)
{
int lII = Ill(++III);
printf(IlI[lII], lIl);
}
return (int) !!lll;
}
>>
>>52129160
>>not casting everything to void pointers
>>
>>52129206
Forgive me, anything else I could've improved?
>>
>>52119605
>not-using-spinal-case
>>
>>52119961

why do i always feel ache in my balls when seeing c#
>>
>>52128828
He's an educator and a speaker. Many people all over the world send him emails for advice and business. He also spends a lot of time collating political news.
>>
>>52129229
Use C++ and template metaprogramming.
>>
>>52119605
The only reason I use camelCase is because shift is much closer than shift->top row key. the latter interrupts my flow.
>>
File: maxresdefault[1].jpg (134 KB, 2548x1430) Image search: [Google]
maxresdefault[1].jpg
134 KB, 2548x1430
>>52121227
P U Z Z L E P I E C E S

https://www.youtube.com/watch?v=1Og2EBG4N5M
>>
#define CATS_ARE_CUTE (true)

class DomesticCat : public Cat {
public:
// types and enums are CaptialCase
enum Breed { RagDoll, BitsaThisBitsaThat, Manks, UnknownBreed };
enum Gender { Male, Female };
DomesticCat(float age, Gender gender) : Cat() { this->age = age; this->gender = gender; }
// everything else is camelCase
Gender gender() { return gender; }
Breed breed() { return breed; }
void spay() { spayed = true; }
bool gentleman() { return spayed && gender==Male; }
bool lady() { return spayed && gender==Female; }
bool tomcat() { return !spayed && gender==Male; }
bool slut() { return !spayed && gender==Female; }
bool sprays() { return gender==Male && age>0.5f && !spayed }
void sendToCattery() { atCattery = true; }
void takeHome() { atCattery = false; }
bool isHome() { return !atCattery; }
void ageBy(float years) { age += years; }
void isKitten() { return age < 0.5f; }
void isMature() { return age >= 1.0f; }

private:
Breed breed;
Gender gender;
bool spayed;
bool atCattery;
float age;
};
>>
>>52119605
oop: camel case
else: under_score
>>
>>52130287
Whoops, meant to have gender_ and breed_ there because they're mirrored by accessor functions.
>>
lowercase_under_scores = conservative, royal, aryan
camelCase = marxist, zionist, jewish
PascalCase = liberal, queer, goy
ALLCAP = libertarian, curmudgeon, bofh
>>
>>52130287
/an/ pls
>>
>>52127836
i appreciate the response but i actually asked because i started learning programming three days ago and the free course im taking says to pick a style and be consistent. s-sorry
Thread replies: 149
Thread images: 9

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.