What emoticons can you put into class names in your language? [closed] - programming-languages

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've just had a discussion with a developer about naming classes in C#. My final throw away line was, "Let's not put any emoticons in our class names."
I can't think of a way you could put emoticons in C# class names, but I haven't thought too hard about it. Is this possible?
Does any programming language allow it? What would be the best/worst language to be able to perform this in?
Update: The Scheme answer bests answers my question. It was a quick idea after a quick discussion so I'm going to accept after a short amount of time and then move on with my life. Thanks for the responses.

Many Japanese-style emoticons - O_o, v_v and the like - are perfectly legal substrings of identifier names in most languages.

For example in Scheme you have the flexibility to include symbols like :, -, / ... in the names,
(define (:-D x)
(+ x 1))
...
(:-D 9)
output: 10

C# supports any Unicode letter for identifiers, so if you find some suitable for emoticons in the Unicode tables, you can use them. The CLR itself allows far more characters in identifier names, like the typical backtick used in compiler-generated names, so you could get really crazy by defining really strange names in MSIL, and then loading the classes with reflection in C# because it does not support those characters...
The method name oO comes to mind. It's an emoticon in itself (small and large eye), but when called on a reference, it expands to a thought bubble: .oO(Hello).

Slightly off-topic: I was processing filenames the other day and realised that all sorts of faces had appeared in my code:
string number(fn.begin()+fn.rfind('_')+1,fn.begin()+fn.rfind('.'));
And of course there are the right-to-left emoticons you almost always get at the end of lines of C++ code:
mesh->Delete();
Why does C++ look so sad?

In C++, if you name a class/struct _ (a poor decision, but here we go), you can derive from it like this:
struct emoticon_to_the_right_of_this :_{
};
Thinking about this, a class o might be just as good:
struct another_emoticon_to_the_right_of_this :o{
};
Hm. I seem to only come up with sad ones. Is that Freud guy around here today? I do have a question to ask him...

Perl uses :: as a package name separator, which means that an IM client might decide to insert a smiley when I talk about XML::Parser (contains ":P") or Data::Dumper (contains ":D"). Punctuation other than :: isn't recommended in package names, so most "extended" smileys are out of the picture, but if I wanted to be very silly I could reference a variable named ${ ':-)' } -- but it would always have to be referenced using the ${'...'} syntax since it's not a recognizable identifier name :)

At this moment in 2014, Apple have just released Swift yesterday. And I made a short example for this. It compiles and runs perfectly fine. :D

I believe I've seen languages that use => to access object attributes (something like person=>father)
It's not actually part of the name, but it could be an emoticon.

Not strictly class names, but there are a few that pop up in PHP from time to time, like an underscore in single quote when concatenating:
$foo = $bar.'_'.$baz;
And as someone else pointed out, you don't even really need special symbols for some of them:
class o_0 {}
class v_v {}
class T_T {}
Something more convoluted:
function d() { echo 'Thumbs up!!'; }
d('_');

Related

Python object attributes named after the object [duplicate]

In other languages, a general guideline that helps produce better code is always make everything as hidden as possible. If in doubt about whether a variable should be private or protected, it's better to go with private.
Does the same hold true for Python? Should I use two leading underscores on everything at first, and only make them less hidden (only one underscore) as I need them?
If the convention is to use only one underscore, I'd also like to know the rationale.
Here's a comment I left on JBernardo's answer. It explains why I asked this question and also why I'd like to know why Python is different from the other languages:
I come from languages that train you to think everything should be only as public as needed and no more. The reasoning is that this will reduce dependencies and make the code safer to alter. The Python way of doing things in reverse -- starting from public and going towards hidden -- is odd to me.
When in doubt, leave it "public" - I mean, do not add anything to obscure the name of your attribute. If you have a class with some internal value, do not bother about it. Instead of writing:
class Stack(object):
def __init__(self):
self.__storage = [] # Too uptight
def push(self, value):
self.__storage.append(value)
write this by default:
class Stack(object):
def __init__(self):
self.storage = [] # No mangling
def push(self, value):
self.storage.append(value)
This is for sure a controversial way of doing things. Python newbies hate it, and even some old Python guys despise this default - but it is the default anyway, so I recommend you to follow it, even if you feel uncomfortable.
If you really want to send the message "Can't touch this!" to your users, the usual way is to precede the variable with one underscore. This is just a convention, but people understand it and take double care when dealing with such stuff:
class Stack(object):
def __init__(self):
self._storage = [] # This is ok, but Pythonistas use it to be relaxed about it
def push(self, value):
self._storage.append(value)
This can be useful, too, for avoiding conflict between property names and attribute names:
class Person(object):
def __init__(self, name, age):
self.name = name
self._age = age if age >= 0 else 0
#property
def age(self):
return self._age
#age.setter
def age(self, age):
if age >= 0:
self._age = age
else:
self._age = 0
What about the double underscore? Well, we use the double underscore magic mainly to avoid accidental overloading of methods and name conflicts with superclasses' attributes. It can be pretty valuable if you write a class to be extended many times.
If you want to use it for other purposes, you can, but it is neither usual nor recommended.
EDIT: Why is this so? Well, the usual Python style does not emphasize making things private - on the contrary! There are many reasons for that - most of them controversial... Let us see some of them.
Python has properties
Today, most OO languages use the opposite approach: what should not be used should not be visible, so attributes should be private. Theoretically, this would yield more manageable, less coupled classes because no one would change the objects' values recklessly.
However, it is not so simple. For example, Java classes have many getters that only get the values and setters that only set the values. You need, let us say, seven lines of code to declare a single attribute - which a Python programmer would say is needlessly complex. Also, you write a lot of code to get one public field since you can change its value using the getters and setters in practice.
So why follow this private-by-default policy? Just make your attributes public by default. Of course, this is problematic in Java because if you decide to add some validation to your attribute, it would require you to change all:
person.age = age;
in your code to, let us say,
person.setAge(age);
setAge() being:
public void setAge(int age) {
if (age >= 0) {
this.age = age;
} else {
this.age = 0;
}
}
So in Java (and other languages), the default is to use getters and setters anyway because they can be annoying to write but can spare you much time if you find yourself in the situation I've described.
However, you do not need to do it in Python since Python has properties. If you have this class:
class Person(object):
def __init__(self, name, age):
self.name = name
self.age = age
...and then you decide to validate ages, you do not need to change the person.age = age pieces of your code. Just add a property (as shown below)
class Person(object):
def __init__(self, name, age):
self.name = name
self._age = age if age >= 0 else 0
#property
def age(self):
return self._age
#age.setter
def age(self, age):
if age >= 0:
self._age = age
else:
self._age = 0
Suppose you can do it and still use person.age = age, why would you add private fields and getters and setters?
(Also, see Python is not Java and this article about the harms of using getters and setters.).
Everything is visible anyway - and trying to hide complicates your work
Even in languages with private attributes, you can access them through some reflection/introspection library. And people do it a lot, in frameworks and for solving urgent needs. The problem is that introspection libraries are just a complicated way of doing what you could do with public attributes.
Since Python is a very dynamic language, adding this burden to your classes is counterproductive.
The problem is not being possible to see - it is being required to see
For a Pythonista, encapsulation is not the inability to see the internals of classes but the possibility of avoiding looking at it. Encapsulation is the property of a component that the user can use without concerning about the internal details. If you can use a component without bothering yourself about its implementation, then it is encapsulated (in the opinion of a Python programmer).
Now, if you wrote a class you can use it without thinking about implementation details, there is no problem if you want to look inside the class for some reason. The point is: your API should be good, and the rest is details.
Guido said so
Well, this is not controversial: he said so, actually. (Look for "open kimono.")
This is culture
Yes, there are some reasons, but no critical reason. This is primarily a cultural aspect of programming in Python. Frankly, it could be the other way, too - but it is not. Also, you could just as easily ask the other way around: why do some languages use private attributes by default? For the same main reason as for the Python practice: because it is the culture of these languages, and each choice has advantages and disadvantages.
Since there already is this culture, you are well-advised to follow it. Otherwise, you will get annoyed by Python programmers telling you to remove the __ from your code when you ask a question in Stack Overflow :)
First - What is name mangling?
Name mangling is invoked when you are in a class definition and use __any_name or __any_name_, that is, two (or more) leading underscores and at most one trailing underscore.
class Demo:
__any_name = "__any_name"
__any_other_name_ = "__any_other_name_"
And now:
>>> [n for n in dir(Demo) if 'any' in n]
['_Demo__any_name', '_Demo__any_other_name_']
>>> Demo._Demo__any_name
'__any_name'
>>> Demo._Demo__any_other_name_
'__any_other_name_'
When in doubt, do what?
The ostensible use is to prevent subclassers from using an attribute that the class uses.
A potential value is in avoiding name collisions with subclassers who want to override behavior, so that the parent class functionality keeps working as expected. However, the example in the Python documentation is not Liskov substitutable, and no examples come to mind where I have found this useful.
The downsides are that it increases cognitive load for reading and understanding a code base, and especially so when debugging where you see the double underscore name in the source and a mangled name in the debugger.
My personal approach is to intentionally avoid it. I work on a very large code base. The rare uses of it stick out like a sore thumb and do not seem justified.
You do need to be aware of it so you know it when you see it.
PEP 8
PEP 8, the Python standard library style guide, currently says (abridged):
There is some controversy about the use of __names.
If your class is intended to be subclassed, and you have attributes that you do not want subclasses to use, consider naming them with double leading underscores and no trailing underscores.
Note that only the simple class name is used in the mangled name, so if a subclass chooses both the same class name and attribute name,
you can still get name collisions.
Name mangling can make certain uses, such as debugging and __getattr__() , less convenient. However the name mangling algorithm is well documented and easy to perform manually.
Not everyone likes name mangling. Try to balance the need to avoid accidental name clashes with potential use by advanced callers.
How does it work?
If you prepend two underscores (without ending double-underscores) in a class definition, the name will be mangled, and an underscore followed by the class name will be prepended on the object:
>>> class Foo(object):
... __foobar = None
... _foobaz = None
... __fooquux__ = None
...
>>> [name for name in dir(Foo) if 'foo' in name]
['_Foo__foobar', '__fooquux__', '_foobaz']
Note that names will only get mangled when the class definition is parsed:
>>> Foo.__test = None
>>> Foo.__test
>>> Foo._Foo__test
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Foo' has no attribute '_Foo__test'
Also, those new to Python sometimes have trouble understanding what's going on when they can't manually access a name they see defined in a class definition. This is not a strong reason against it, but it's something to consider if you have a learning audience.
One Underscore?
If the convention is to use only one underscore, I'd also like to know the rationale.
When my intention is for users to keep their hands off an attribute, I tend to only use the one underscore, but that's because in my mental model, subclassers would have access to the name (which they always have, as they can easily spot the mangled name anyways).
If I were reviewing code that uses the __ prefix, I would ask why they're invoking name mangling, and if they couldn't do just as well with a single underscore, keeping in mind that if subclassers choose the same names for the class and class attribute there will be a name collision in spite of this.
I wouldn't say that practice produces better code. Visibility modifiers only distract you from the task at hand, and as a side effect force your interface to be used as you intended. Generally speaking, enforcing visibility prevents programmers from messing things up if they haven't read the documentation properly.
A far better solution is the route that Python encourages: Your classes and variables should be well documented, and their behaviour clear. The source should be available. This is far more extensible and reliable way to write code.
My strategy in Python is this:
Just write the damn thing, make no assumptions about how your data should be protected. This assumes that you write to create the ideal interfaces for your problems.
Use a leading underscore for stuff that probably won't be used externally, and isn't part of the normal "client code" interface.
Use double underscore only for things that are purely convenience inside the class, or will cause considerable damage if accidentally exposed.
Above all, it should be clear what everything does. Document it if someone else will be using it. Document it if you want it to be useful in a year's time.
As a side note, you should actually be going with protected in those other languages: You never know your class might be inherited later and for what it might be used. Best to only protect those variables that you are certain cannot or should not be used by foreign code.
You shouldn't start with private data and make it public as necessary. Rather, you should start by figuring out the interface of your object. I.e. you should start by figuring out what the world sees (the public stuff) and then figure out what private stuff is necessary for that to happen.
Other language make difficult to make private that which once was public. I.e. I'll break lots of code if I make my variable private or protected. But with properties in python this isn't the case. Rather, I can maintain the same interface even with rearranging the internal data.
The difference between _ and __ is that python actually makes an attempt to enforce the latter. Of course, it doesn't try really hard but it does make it difficult. Having _ merely tells other programmers what the intention is, they are free to ignore at their peril. But ignoring that rule is sometimes helpful. Examples include debugging, temporary hacks, and working with third party code that wasn't intended to be used the way you use it.
There are already a lot of good answers to this, but I'm going to offer another one. This is also partially a response to people who keep saying that double underscore isn't private (it really is).
If you look at Java/C#, both of them have private/protected/public. All of these are compile-time constructs. They are only enforced at the time of compilation. If you were to use reflection in Java/C#, you could easily access private method.
Now every time you call a function in Python, you are inherently using reflection. These pieces of code are the same in Python.
lst = []
lst.append(1)
getattr(lst, 'append')(1)
The "dot" syntax is only syntactic sugar for the latter piece of code. Mostly because using getattr is already ugly with only one function call. It just gets worse from there.
So with that, there can't be a Java/C# version of private, as Python doesn't compile the code. Java and C# can't check if a function is private or public at runtime, as that information is gone (and it has no knowledge of where the function is being called from).
Now with that information, the name mangling of the double underscore makes the most sense for achieving "private-ness". Now when a function is called from the 'self' instance and it notices that it starts with '__', it just performs the name mangling right there. It's just more syntactic sugar. That syntactic sugar allows the equivalent of 'private' in a language that only uses reflection for data member access.
Disclaimer: I have never heard anybody from the Python development say anything like this. The real reason for the lack of "private" is cultural, but you'll also notice that most scripting/interpreted languages have no private. A strictly enforceable private is not practical at anything except for compile time.
First: Why do you want to hide your data? Why is that so important?
Most of the time you don't really want to do it but you do because others are doing.
If you really really really don't want people using something, add one underscore in front of it. That's it... Pythonistas know that things with one underscore is not guaranteed to work every time and may change without you knowing.
That's the way we live and we're okay with that.
Using two underscores will make your class so bad to subclass that even you will not want to work that way.
The chosen answer does a good job of explaining how properties remove the need for private attributes, but I would also add that functions at the module level remove the need for private methods.
If you turn a method into a function at the module level, you remove the opportunity for subclasses to override it. Moving some functionality to the module level is more Pythonic than trying to hide methods with name mangling.
Following code snippet will explain all different cases :
two leading underscores (__a)
single leading underscore (_a)
no underscore (a)
class Test:
def __init__(self):
self.__a = 'test1'
self._a = 'test2'
self.a = 'test3'
def change_value(self,value):
self.__a = value
return self.__a
printing all valid attributes of Test Object
testObj1 = Test()
valid_attributes = dir(testObj1)
print valid_attributes
['_Test__a', '__doc__', '__init__', '__module__', '_a', 'a',
'change_value']
Here, you can see that name of __a has been changed to _Test__a to prevent this variable to be overridden by any of the subclass. This concept is known as "Name Mangling" in python.
You can access this like this :
testObj2 = Test()
print testObj2._Test__a
test1
Similarly, in case of _a, the variable is just to notify the developer that it should be used as internal variable of that class, the python interpreter won't do anything even if you access it, but it is not a good practise.
testObj3 = Test()
print testObj3._a
test2
a variable can be accesses from anywhere it's like a public class variable.
testObj4 = Test()
print testObj4.a
test3
Hope the answer helped you :)
At first glance it should be the same as for other languages (under "other" I mean Java or C++), but it isn't.
In Java you made private all variables that shouldn't be accessible outside. In the same time in Python you can't achieve this since there is no "privateness" (as one of Python principles says - "We're all adults"). So double underscore means only "Guys, do not use this field directly". The same meaning has singe underscore, which in the same time doesn't cause any headache when you have to inherit from considered class (just an example of possible problem caused by double underscore).
So, I'd recommend you to use single underscore by default for "private" members.
"If in doubt about whether a variable should be private or protected, it's better to go with private." - yes, same holds in Python.
Some answers here say about 'conventions', but don't give the links to those conventions. The authoritative guide for Python, PEP 8 states explicitly:
If in doubt, choose non-public; it's easier to make it public later than to make a public attribute non-public.
The distinction between public and private, and name mangling in Python have been considered in other answers. From the same link,
We don't use the term "private" here, since no attribute is really private in Python (without a generally unnecessary amount of work).
#EXAMPLE PROGRAM FOR Python name mangling
class Demo:
__any_name = "__any_name"
__any_other_name_ = "__any_other_name_"
[n for n in dir(Demo) if 'any' in n] # GIVES OUTPUT AS ['_Demo__any_name',
# '_Demo__any_other_name_']

Sublime Text 3 custom syntax for cottle: hard to start

I'm trying to make a "very simple" syntax highlight for "cottle" (which is a script language used in a text-to-speech app dedicated to Elite:Dangerous).
All i want (at least at the beginning) is to have three different colours: Comments, "non-strings", and strings.
I started trying with the ST3 wiki, youtube tutorials, questions here.... but i can't sort out how to do it, 'cause the way the language work.
I'll try to show you an example
{ everything_between_a_pair_of_brackets_is_code }
everything outside all pairs of bracket is a string {_ and this is a comment. It begins with "_" and ends at the closing bracket }
{ This_is_code("but this is a string")
This_is_still_code("this is also a string {but_this_is_code(\"and a string\")} and this the end of the string")
}
My problem is how to define this kind of "nidification" in my cottle.sublime-syntax file. I managed to get the comment, but only the first one.
- EDIT -
This is a real script:
{event.item}
{if event.repairedfully:
fully repaired
|else:
partially repaired
{Occasionally(2,
cat(
OneOf("to ", "at "),
Humanise(event.health * 100),
" percent functionality"
)
)}
}
{Occasionally(2,
cat(OneOf(", ", "and is"), " ready for re-activation")
)}.
The output of this script could be "Engine module fully repaired." or "Engine module partially repaired, and is ready for re-activation."
Please note the last dot of the phrase, which in the code is after the last bracket.
This is another sample, with strings passed to functions inside other strings:
{OneOf("{ShipName()} has", "")}
{OneOf("left supercruise", "{OneOf(\"entered\", \"returned to\", \"dropped to\")} normal space")}
My question is:
how sublime-syntax files handle this kind of nidification?
Looking at the overview of the templating language over at https://cottle.readthedocs.io/en/stable/page/01-overview.html, it seems to be an easy syntax for which to write a .sublime-syntax for, but given the utter lack of resources for knowing how syntax files works in ST, I can understand it can be sometimes difficult to start or even understand.
So, I took the liberty of creating a starter syntax definition (the result of an hour & a half of boredom on a Saturday evening), which you can take and work upon. Note that I have not used the language and as such made it by just reading the docs and looking over code snippets.
You can find a gist for it here (https://gist.github.com/Ultra-Instinct-05/96fa99e1aaeb32b12d1e62109d61fcc2)
Here is a screenshot showing it in the color scheme I use (which follows the official scope naming guidelines).
It still lacks support for user defined functions (as I came to know from the docs) (and probably a few other things), but maybe that's something you can add to it !
Note that to use it, save the file as Cottle.sublime-syntax in your User package. Right now files having a .cottle extension are highlighted (because I don't know how you create a cottle file).
The syntax definition doesn't use any new feature added in ST4, so it should work the same in both ST3 & ST4.

Creating Sublime Text 3 syntax for obscure language

There's a coding language called SugarCube designed for use in the Twine engine, which is used for text adventure games. Here's the Documentation for it. I'm not exactly an experienced coder - all I have is a few months in C# making a game in Unity - but I'd like to help a friend with his game, and hopefully writing his code in an editor instead of plaintext will help.
The only kind of code that matters is all marked with double angle brackets. Variables are marked with dollar signs $exampleVarand are declared and assigned using
<<set $exampleVar = "foo">>.
If and switch statements use closing tags similar to HTML:
<<if $exampleVar == "foo">>
// code
<</if>>
or
<<switch $exampleVar>>
<<case "foo">>
// code
<</switch>>
The guides I've found for custom syntax (including official documentation) are either outdated or assume you already know everything about YAML, which I don't. Advice?

What old language is this?

A friend of mine sended bunch of code for me to build a software. However, I do not recognize language and my friend is no coder. One thing I'm sure about though. The code is something like 20-40 years old.
Code was originally used in electrical works.
Character limit per line seems to be 20 characters.
Can someone recognize this language? I'm also looking for manuals for this language if possible.
10:"K": PAUSE "IK":
CLEAR
15:P=1: INPUT "ETR=PRIN
T, 0=NO? ";P
20:DIM L(20),R(20),X(20
),B(1),G(1),Q(1),O$(
1)*24
22:IF P=1 INPUT "K. /DA
TE? ";O$(0)
24:IF P=0 GOTO 30
26:INPUT "N:0 AND NAME?
"; O$(1)
28:LPRINT O$(1): LPRINT
"KKS/";OS(0)
30:INPUT "(KVA)? ";S
35:IF P=1 LPRINT "KVA",
S
40:R=3.31 :Z=4
...
I searched for this language and PowerBasic seems to be close to it, but it contains many other features what this code lacks. Any guesses?
Edit 1
It seems that there were typos. No wonder "P=!" or "0$(0) didn't make any sense.
Edit 2
I accepted Gaby's answer because code seems to be very close to GW-Basic. Also found a manual for the language which works perfectly: http://www.antonis.de/qbebooks/gwbasman/
Thanks for the help!
Edit 3
Got some new information. Language might actually be something called "Nova Basic" from 1975. I'm unable to find manual for that language, but at least this gives me a new direction.
It's definitely a BASIC variant, one of those like in the early micro-computer days, before things like VB and structured coding came into play :-)
However, it has a few non-recognisable aspects such as:
the statement "K".
the assignment P=!, unless that ! should be a 1.
the use of variables starting with a numeric: 0$(0), unless you've mistakenly typed an O (owe) in as a 0 (zero).
None of those were very common in BASICs of the day though keep in mind the language wasn't standardised to the same level as something like C is nowadays. Everything else seems pretty standard: input, printing, assignment, array dimensioning, and so on.
Given the line length limit, the domain (KKS and KVA are both electrical terms) and the weird syntax variations, I'd say it was for one of the early programmable calculators, such as Casio, Texas Instruments or Sharp (though not necessarily those specific brands).
It reminds me of GW-BASIC
Example code at http://fr.wikipedia.org/wiki/GW-BASIC
Not a lot information in your code. Maybe QBASIC ? http://fr.wikipedia.org/wiki/QBasic

What's the name for hyphen-separated case?

This is PascalCase: SomeSymbol
This is camelCase: someSymbol
This is snake_case: some_symbol
So my questions is whether there is a widely accepted name for this: some-symbol? It's commonly used in url's.
There isn't really a standard name for this case convention, and there is disagreement over what it should be called.
That said, as of 2019, there is a strong case to be made that kebab-case is winning:
https://trends.google.com/trends/explore?date=all&q=kebab-case,spinal-case,lisp-case,dash-case,caterpillar-case
spinal-case is a distant second, and no other terms have any traction at all.
Additionally, kebab-case has entered the lexicon of several javascript code libraries, e.g.:
https://lodash.com/docs/#kebabCase
https://www.npmjs.com/package/kebab-case
https://v2.vuejs.org/v2/guide/components-props.html#Prop-Casing-camelCase-vs-kebab-case
However, there are still other terms that people use. Lisp has used this convention for decades as described in this Wikipedia entry, so some people have described it as lisp-case. Some other forms I've seen include caterpillar-case, dash-case, and hyphen-case, but none of these is standard.
So the answer to your question is: No, there isn't a single widely-accepted name for this case convention analogous to snake_case or camelCase, which are widely-accepted.
It's referred to as kebab-case. See lodash docs.
It's also sometimes known as caterpillar-case
This is the most famous case and It has many names
kebab-case: It's the name most adopted by official software
caterpillar-case
dash-case
hyphen-case or hyphenated-case
lisp-case
spinal-case
css-case
slug-case
friendly-url-case
As the character (-) is referred to as "hyphen" or "dash", it seems more natural to name this "dash-case", or "hyphen-case" (less frequently used).
As mentioned in Wikipedia, "kebab-case" is also used. Apparently (see answer) this is because the character would look like a skewer... It needs some imagination though.
Used in lodash lib for example.
Recently, "dash-case" was used by
Angular (https://angular.io/guide/glossary#case-types)
NPM modules
https://www.npmjs.com/package/case-dash (removed ?)
https://www.npmjs.com/package/dasherize
Adding the correct link here Kebab Case
which is All lowercase with - separating words.
I've always called it, and heard it be called, 'dashcase.'
There is no standardized name.
Libraries like jquery and lodash refer it as kebab-case. So does Vuejs javascript framework. However, I am not sure whether it's safe to declare that it's referred as kebab-case in javascript world.
I've always known it as kebab-case.
On a funny note, I've heard people call it a SCREAM-KEBAB when all the letters are capitalized.
Kebab Case Warning
I've always liked kebab-case as it seems the most readable when you need whitespace. However, some programs interpret the dash as a minus sign, and it can cause problems as what you think is a name turns into a subtraction operation.
first-second // first minus second?
ten-2 // ten minus two?
Also, some frameworks parse dashes in kebab cased property. For example, GitHub Pages uses Jekyll, and Jekyll parses any dashes it finds in an md file. For example, a file named 2020-1-2-homepage.md on GitHub Pages gets put into a folder structured as \2020\1\2\homepage.html when the site is compiled.
Snake_case vs kebab-case
A safer alternative to kebab-case is snake_case, or SCREAMING_SNAKE_CASE, as underscores cause less confusion when compared to a minus sign.
I'd simply say that it was hyphenated.
Worth to mention from abolish:
https://github.com/tpope/vim-abolish/blob/master/doc/abolish.txt#L152
dash-case or kebab-case
In Salesforce, It is referred as kebab-case. See below
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.js_props_names
Here is a more recent discombobulation. Documentation everywhere in angular JS and Pluralsight courses and books on angular, all refer to kebab-case as snake-case, not differentiating between the two.
Its too bad caterpillar-case did not stick because snake_case and caterpillar-case are easily remembered and actually look like what they represent (if you have a good imagination).
My ECMAScript proposal for String.prototype.toKebabCase.
String.prototype.toKebabCase = function () {
return this.valueOf().replace(/-/g, ' ').split('')
.reduce((str, char) => char.toUpperCase() === char ?
`${str} ${char}` :
`${str}${char}`, ''
).replace(/ * /g, ' ').trim().replace(/ /g, '-').toLowerCase();
}
This casing can also be called a "slug", and the process of turning a phrase into it "slugify".
https://hexdocs.pm/slugify/Slug.html

Resources