Idea to extend programming languages with plurals.

Here’s a nice idea to make programming languages nicer. Its an idea you might like to use if you are creating a new scripting language for your game. Basically the idea is to add plural names to classes and lists. Best demonstrated with some examples.

class Goose (pl=Geese){
   //class definition
}

List<Geese> my_goose (pl=my_geese);

for(int i=0;i<my_geese.length;i++){
    Debug.Log(my_goose[i])
}

For usual words like cat(s) you would not have to specify the plural. There would be absolutely no benefit for this system except to make the programmer happier. I don’t see why programmers shouldn’t be able to use plurals. It seems such a minor thing to implement into a programming language! Otherwise it doesn’t really make grammatical sense. If you call your list of geese, “geese” then to get the fifth member you write “geese[5]”, “the fifth geese” which is not grammatical. Or if you called the list “goose” that doesn’t make sense either to call a list something singular.

In terms of model, frameworks like Rails already do that, it is done through Inflections. Beyond something like that, it doesn’t make much sense. It doesn’t solve any problems, and introduces unneeded complexity, and potential as “hidden” variable names are created. It also is a grammar fail. The index number indicates that it is part of a collection. geese[5] means it is the is the sixth element in ‘geese’ goose[5] is the sixth goose? goose isn’t a collection, geese is. Grammar is structural rules of the language. Besides it is common to use inflections in architecture anyway, adding it at the language level isn’t helpful.

5 Likes

Convoluted rules never make anything better. What you’re describing would be acceptable for an esoteric language but not for a language you expect to do actual work in.

What will be the rules for determining the plural form of the word? What will happen if someone typos the word?

3 Likes

Indeed, and moreover, why add an extraneous knowledge requirement unnecessarily? If weren’t a native English speaker, it would just add pointless confusion. I don’t know many Swedish words, let alone their plurals. Yet I work with several Swedes, and I can read their code just fine.

2 Likes

Sounds like a nightmare. What would be the upside?

Try stepping into an ‘easier’ language for a while. VBA is a good one. You’ll find that all of the shortcuts actually makes it more difficult to build anything complex.

Dude, that looks like a complete mess.

It’s almost as bad as… as Javascript

3 Likes

One thing to think about when you’re trying to improve something is how many opportunities for errors or mistakes you’re adding.

In your example, you still need to know all of the existing programming rules about using collections, and then there’s the added knowledge requirement* of declaring a variant of the Goose type that can only be used in collections, and then the added identifiers in your code to refer specifically to those types. So there’s added opportunities for mistakes in the syntax, in creating and using the correct identifiers in the correct places, and in tracking a bunch of extra identifiers.

Separately, there’s potential language issues. What’s the plural of “Sheep”?

Personally I find that programming languages often make more sense than spoken ones, in large part because there are fewer arbitrary rules.

In that regard, spoken languages really need to pull their socks up.**

  • I know you’ve said it’s optional, but someone will use it, so everyone has to understand it.
    ** “Pulling your socks up” is a completely arbitrary set of words that, in English speaking countries, means “make improvements” or “do your job properly”. It has nothing whatsoever to do with adjustment of footwear.
1 Like

like what are you trying to improve with this, collections work just fine as it is.

1 Like

In Rails, the pluralization is part of the scaffolding for the model (and use by the controller). It’s all based on table names. For words without plurals, (sheep, fish, police, etc), the scaffolding names the plural class “sheep_index”. So the plural of sheep is sheep_index. :wink:

3 Likes

Your posts are leaving me with the distinct impression that I’m glad I never learned Rails. :stuck_out_tongue:

1 Like

Rails is a thing of beauty and elegance, truly. It’s very different, but very, very logical.

Ok.

4 Likes

He’s gone off the rails.

4 Likes

Rails is/was the defacto standard for Rest, the ActiveRecord pattern, and quite a number of other improvements that were adopted by most of the web frameworks we use today. The ruby community in general was a major force behind the adoption of some of the better unit testing patterns and tools out there.

Inflections and just generally code that reads more like natural language is much more popular in languages that have first class support for metaprogramming. So many ruby libraries are basically just DSL’s. Cucumber is a good example of how far you can carry the paradigm.

In statically typed languages it just doesn’t really work. Not that some haven’t tried over the years.

1 Like

Indeed. I only mentioned it because pluralization and sheep were mentioned, my mind immediately went to Rails. Inflections and such are nice for certain types of things like frameworks, but not good for languages.

Hold on. Let’s be a bit less specific here.
.
Aren’t you just assigning additional labels to variable names and class names?
It’s not like you’ve expended functionality to the point that compiler will know whether you’re referring to a list or not with “my_goose” or “my_geese”.
I mean, you refer to the list in 2 ways but never address a singular entity.

for(int i=0;i<my_geese.length;i++){//List name
    Debug.Log(my_goose[i])//Still list name
}

And if you want it to be more strict, what are you going to do with “deer”, “moose”, “bison”, “sheep” or “swine”? :slight_smile:

Personally I just don’t think letting linguistics anywhere close to programming is a good idea.

1 Like

That’s a good point. Originally I thought that the plural name would automatically define a list. But then the “one sheep” “two sheep” problem. :frowning: Although I still can never decide whether to call a list of things: “thing” or “things”. What is the common practice? Maybe “thingList”

I don’t think there’s conventions outside DB design.
I usually just throw linguistics under the bus and add as many "s"s as required to make sure reader understands it’s an array. :stuck_out_tongue:

List<Sheep> Sheeps = new List<Sheep>();
3 Likes

hahah :smile:

Yeah, I use unambiguous plurals or explicitly call it some type of collection.

There’s also natural group names to muddy things up. For instance, a “class” is a collection of students. “Class” is not plural, but may still represent a collection, and a collection of “classes” would be a collection of collections. Same deal with flocks, schools (fish), teams and so on.

Of course I’d just do my best to make things abundantly clear in my design / implementation / docs if I were to use that in code. Including giving due consideration to avoiding such names.