50
Jan 24 '17
PascalCase.. camelCase.. snake_case.. I recommend the kebab-case.
27
u/mort96 Jan 24 '17
Far too few languages support kebab-case (or as I've heard it, dash-case). Way nicer than snake_case, doesn't have annoying capitalization edge cases like camelCase or PascalCase (e.g should it be getElementByID or getElementById? XMLHttpRequest or XMLHTTPRequest or XmlHttpRequest?)
20
u/MaxxDelusional Jan 24 '17
I was always an 'ID' kind of guy, but lately, I've been training myself to be more of an 'Id' guy. Seems to be more inline with the way the rest of the world writes it.
39
u/Kattzalos Jan 25 '17
I just use iD, looks way more slick. And programming is all about writing the coolest code possible
9
u/idi0tf0wl Jan 25 '17
snake_case is a real pain in the ass on most keyboards. Japanese keyboards, at least, have a dedicated key for underscore, which makes snake_case infinitely nicer to work with.
19
u/Kattzalos Jan 25 '17
you should try a Spanish keyboard. 90% of the punctuation you need for programming needs modifier keys. but at least I get this slick ñ key
7
6
u/YRYGAV Jan 27 '17
Doing it like 'XmlHttpRequest' removes any ambiguity.
kebab-case can have edge cases if you have a word that has a hyphen, or 2 words that could have a hyphen, ala xkcd. Such as does
sugar-free-donutsmean donuts with no sugar, or free sugar donuts?3
u/xkcd_transcriber Jan 27 '17
Title: Hyphen
Title-text: I do this constantly
Stats: This comic has been referenced 4613 times, representing 3.1615% of referenced xkcds.
xkcd.com | xkcd sub | Problems/Bugs? | Statistics | Stop Replying | Delete
1
u/mort96 Jan 27 '17
I would argue that if you don't intentionally misread the name, as is the case in the XKCD,
sugar-free-donutswould be read as donuts with no sugar, whilefree-sugar-donutswould be read as free sugar donuts.I kind of agree that XmlHttpRequest is nicer, but at the same time, I really don't like how
Idlooks. There's also the problem with one character words.ThingsIMadelooks way less nice and less readable thanthings-i-made, imo.1
5
3
Jan 25 '17
A snake_cased word is generally considered one complete word, whereas a hyphenated word is considered two.
This affects the behavior of ctrl-left/right when navigating in a text editor.
1
u/mort96 Jan 25 '17
That's probably true, I hadn't considered that. However, in at least vim, and presumably most other editors, you can change the settings such that a hyphen is considered part of the word, and even if you don't do that, it's not exactly a huge issue.
1
1
1
8
6
2
1
1
21
u/utopianfiat Jan 24 '17
Every case but snake_case is deprecated. Netcraft confirmed it.
29
u/Kattzalos Jan 24 '17
I'm making a new programming language, I call it phpscript. variable names can include any character, including spaces. say goodbye to case conventions, you can just write a phrase like a god damn person would
10
Jan 24 '17
Good luck writing the interpreter.
15
5
Jan 25 '17
Yeah but then make it case insensitive.
Wait no don't do that.
Wait, actually, do it.
Ok just functions how about.
Ok yeah only functions are case insensitive.
Got it.
3
u/afraca Jan 25 '17
Using phrases in programming reminds me of Applescript, look at https://en.wikipedia.org/wiki/AppleScript#Natural_language_metaphor
2
u/idi0tf0wl Jan 25 '17
I really hated snake_case until I started working on a Japanese keyboard, which has a dedicated key for underscore. Suddenly the one thing I hated about Ruby made sense.
0
Jan 25 '17
[deleted]
1
u/idi0tf0wl Jan 26 '17
Except with PascalCase it's one fewer keystroke, since you're modifying the letter of the next word instead of the word separator.
0
Jan 26 '17
[deleted]
0
u/idi0tf0wl Jan 28 '17
It's not about the number of characters, it's about the number of keystrokes.
1
Jan 28 '17 edited Jan 28 '17
One extra, if it was pascal case but a character longer it would be the same...
1
u/idi0tf0wl Jan 29 '17
What are you even saying right now? ThisObjectName is easier to type than this_object_name, and thisObjectName is even easier. Every underscore breaks the flow of what you're typing because key placement insists you either use Left Shift for it or contort your right hand into leaving where it should be, whereas when using camelCase or PascalCase you can use whichever Shift key makes the most sense and move on. For this reason alone, camelCase and PascalCase are easier to type on, say, a U.S. keyboard — it's really not a matter of opinion unless you just actually don't do all that much typing, or don't have enough faith in your code to write more than one line at a time. It's a question of ergonomics. Is snake_case more readable? Yeah, I'd argue that it is. But it's definitely not easier to type.
Unless you've got a dedicated underscore key (which I do on my Japanese machine), in which case this_object_name becomes significantly easier than either thisObjectName or ThisObjectName.
Even so, I still prefer the Sun Java case conventions as I find them the most intuitive to work with. That is a matter of opinion.
1
Jan 29 '17
And you have a problem to type 2 characters more? For pascal case it's even 1 character longer.
Is this that of a big of a deal?
1
u/idi0tf0wl Jan 29 '17
Nothing I just said has anything to do with character counts…
Even so, on what planet does ThisObjectName have more characters than this_object_name?
1
0
6
8
u/idi0tf0wl Jan 25 '17
I was pretty confused by this thread until I realised we were discussing C# and not Java. That is, Java with weird brackets and PascalCase method names, and not Java for reasonable people.
8
u/sou1eater Jan 24 '17 edited Jan 24 '17
Also, because this is an extension method, the null case will never be hit. Edit: See Kilazur below! I am incorrect :)
24
u/Kilazur Jan 24 '17
It's apparently wrong, but I never thought about it. Glad I learned something new today :D
12
u/sou1eater Jan 24 '17
Excellent find, thanks!
11
u/dazerdude Jan 24 '17
IIRC, extension methods just get translated to normal static method calls when C# is compiled. It's just a bit of syntactic sugar on top of some compiler search rules.
5
u/thelehmanlip Jan 24 '17
Yes! One of my favorite extension methods is based on this fact:
public static IEnumerable<T> OrEmptyIfNull(this IEnumerable<T> obj) { return obj ?? Enumerable.Empty<T>(); }6
u/MaxxDelusional Jan 24 '17
I'm a fan of these as well
public static string EmptyIfNull(this string s) { return s ?? String.Empty; } public static string NullIfEmpty(this string s) { return (String.IsNullOrWhitespace(s) ? null : s); }4
13
u/nucular_ Jan 24 '17
To be fair, PascalCase is pretty terrible
43
25
u/z500 Jan 24 '17
After working with .NET for a year and a half, method names don't look right anymore in camelCase.
7
u/markusmeskanen Jan 24 '17
Same applies to any language though, PascalCase looks horrible now that I've gone python_mode
8
Jan 24 '17
I always juggle at least two languages. Right now it's C# and Python with the occasional JS. Nothing looks weird to me anymore.
1
6
u/PM_ME_YOUR_APP_IDEA Jan 24 '17
Why? I was a Java dev, now a C# dev for nearly 2 years, and thinking about doing Swift soon.
As long as each language has their own structure and everyone keeps to it, what's the problem?
9
2
-32
u/OrionBlastar Jan 24 '17
Recursion is recursion until it ends with an infinite loop. Stack Overflows are funny that way.
27
u/robot_lords Jan 24 '17 edited Dec 15 '23
cautious elderly rinse snatch zephyr support foolish compare automatic spotted
This post was mass deleted and anonymized with Redact
0
Jan 24 '17
[deleted]
12
u/OrionBlastar Jan 24 '17
Better use HolyC and TempleOS because it is really secure. That is because it does not have Network or TCP/IP support.
6
-21
u/caagr98 Jan 24 '17
WTF is PascalCase? It's called CamelCase (not to be confused with camelCase).
18
u/mort96 Jan 24 '17
You just pointed out yourself why it's useful to have a different word for PascalCase and camelCase.
PascalCase is a pretty common term for it: https://en.wikipedia.org/wiki/PascalCase
60
u/TinBryn Jan 24 '17