Subject/Object/Verb ordering in code

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

Which do you prefer?

int coord_x_get(coord); //SOV
0
No votes
int coord_get_x(coord); //SVO
4
25%
int get_coord_x(coord); //VSO
6
38%
int get_x_coord(coord); //VOS
6
38%
int x_get_coord(coord); //OVS
0
No votes
int x_coord_get(coord); //OSV
0
No votes
 
Total votes: 16

LambdaBeta
Posts: 3
Joined: Tue Jan 28, 2014 8:06 pm UTC

Subject/Object/Verb ordering in code

Postby LambdaBeta » Fri Apr 10, 2015 10:00 pm UTC

There are six possible orderings of subjects, objects, and verbs in sentences. By far the most common orderings are Subject-Object-Verb (Latin/Japanese), and Subject-Verb-Object(Mandarin-English). You can read more about this phenomena here: http://en.wikipedia.org/wiki/Word_order.

What I have noticed is that when writing code people suddenly decide that they speak weird esoteric languages.

Here is a sample of the six options for a function to get the x value of a coordinate in c arranged by popularity in spoken languages:

Code: Select all

int coord_x_get(coord); //SOV
int coord_get_x(coord); //SVO
int get_coord_x(coord); //VSO
int get_x_coord(coord); //VOS
int x_get_coord(coord); //OVS
int x_coord_get(coord); //OSV


Which do you tend to prefer? Why?

I like SVO because I speak english, and because it helps with auto-complete. My RTOS professor mandates VOS or OVS since he requires that the "this"-type object is at the end. C++ mandates SOV or SVO, as do most other object-oriented languages (coord.get_x(); coord.x_get();).

I have seen all 6 of these variations in the course of 3 group projects in my Software Engineering program at the University of Waterloo. I find the weirdest to be OSV.

User avatar
Sizik
Posts: 1137
Joined: Wed Aug 27, 2008 3:48 am UTC

Re: Subject/Object/Verb ordering in code

Postby Sizik » Sat Apr 11, 2015 1:12 am UTC

I don't think "coord" is really a subject. I'd describe the function in English as "get the x coordinate", so "x coord" is more like the object with "x" being an adjective.
gmalivuk wrote:
King Author wrote:If space (rather, distance) is an illusion, it'd be possible for one meta-me to experience both body's sensory inputs.
Yes. And if wishes were horses, wishing wells would fill up very quickly with drowned horses.

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Subject/Object/Verb ordering in code

Postby ahammel » Sat Apr 11, 2015 1:42 am UTC

Verb goes first, subject and object are negotiable depending on what's convenient for partial application, usually the object. (I realise that C programmers rarely concern themselves with that.)
He/Him/His/Alex
God damn these electric sex pants!

LambdaBeta
Posts: 3
Joined: Tue Jan 28, 2014 8:06 pm UTC

Re: Subject/Object/Verb ordering in code

Postby LambdaBeta » Sat Apr 11, 2015 3:56 am UTC

@Sizik In this instance coord would be the object whose 'x' we are trying to get. EG:

Code: Select all

coord my_coord = {10,20};
printf("%d",coord_get_x(my_coord));//c-style
cout<<my_coord.get_x();//c++-style


Thus I think it counts as the subject. Perhaps I should have chosen a clearer example.

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3033
Joined: Sat May 09, 2009 11:55 pm UTC

Re: Subject/Object/Verb ordering in code

Postby Qaanol » Sat Apr 11, 2015 4:21 am UTC

Output Preposition Input:
int x = xFromCoordinate(coord);
wee free kings

lalop
Posts: 210
Joined: Mon May 23, 2011 5:29 pm UTC

Re: Subject/Object/Verb ordering in code

Postby lalop » Sat Apr 11, 2015 8:43 am UTC

Why not just get_x(coord)?

More seriously, the example question is ambiguous, because the x-coordinate is a thing. That is, people can understand it either as "how to write getting the x from a coord" or "how to write getting the x-coord". Only with the former interpretation does coord_get_x, for example, make any sense.

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3033
Joined: Sat May 09, 2009 11:55 pm UTC

Re: Subject/Object/Verb ordering in code

Postby Qaanol » Sat Apr 11, 2015 9:04 pm UTC

lalop wrote:Why not just get_x(coord)?

Because the C language, for one, does not support function overloading.
wee free kings

User avatar
Flumble
Yes Man
Posts: 1872
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Subject/Object/Verb ordering in code

Postby Flumble » Sun Apr 12, 2015 3:02 pm UTC

LambdaBeta, if you replace "coord" with "point", we can drop the discussion on x coordinates. :mrgreen:

Sizik wrote:I don't think "coord" is really a subject.

Me too, but for the reason that coord isn't "get"ting anything, the program is getting the coord's x property. Coords are a bit stupid and don't have a will of their own.

officer_arrest_person() (SVO) would be a clearer example.

Note that the word order (for a good programmer) depends on the program's hierarchy.
In the arrest example, if the intended program is an arrest database (or log app or whatever), an arrest performed by an officer of a person would likely be called arrest_officer_person()... hold on, no, the arrest has just gone nominal: it should be perform_arrest_officer_person().

So methinks: SVO if the program is object/actor oriented, VSO if the program is function/process oriented. Just make sure the grammatical object is in last place (optionally followed by more context, like indirect objects and adjuncts), because it is the least important in the command's hierarchy.

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3033
Joined: Sat May 09, 2009 11:55 pm UTC

Re: Subject/Object/Verb ordering in code

Postby Qaanol » Sun Apr 12, 2015 6:52 pm UTC

Flumble wrote:officer_arrest_person() (SVO) would be a clearer example.

I would expect this function to take two parameters (an officer, and a person) and return nothing, along the lines of:
void officerArrestPerson(arrestingOfficer, person);

I really want the return value listed first though, so a void function should start with a verb:
void arrestPersonByOfficer(person, arrestingOfficer);

I want the nouns in the function name to match up with the parameters in order. That allows more complicated functions like:
void arrestPersonInLocationAtTimeByOfficer(person, location, time, arrestingOfficer);

Although, in an object-oriented language, this would probably be a method of Officer objects, so a call would look more like:
officer.arrestPersonInLocationAtTime(person, location, time);
wee free kings

Derek
Posts: 2117
Joined: Wed Aug 18, 2010 4:15 am UTC

Re: Subject/Object/Verb ordering in code

Postby Derek » Sun Apr 12, 2015 11:59 pm UTC

get_coord_x is an imperative statement with no subject. The verb is "get", and the object is "coord x".

In object oriented languages you'll usually something like object.doThing(other). In this case "object" is the subject, "doThing" is the verb, and "other" is the object.

User avatar
phlip
Restorer of Worlds
Posts: 7538
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Subject/Object/Verb ordering in code

Postby phlip » Mon Apr 13, 2015 3:05 am UTC

Subject-verb-object is more of a thing in relation to a declarative mood... "the program got the x-coordinate" - the program is the subject, "to get" is the verb, the x-coordinate is the object. It's for describing things that have happened/are happening/will happen.

In a programming context, it makes more sense to use an imperative... you're telling the computer what to do, not describing what it's doing. In that mood, it's mostly just verb-object. "Get the x-coordinate". If there's a subject in there, it's more you declaring who you're talking to, followed by the imperative phrase... "Program, get the x-coordinate"... it's more "target, verb object" rather than "subject verb object".

That translates into C++-style code relatively cleanly as "verb(object)" and "target.verb(object)". The function/method name should just be a verb, nothing else. If you need to include some additional bits (for clarification or to avoid overloading) then building a more complex verb-phrase via prepositions can be reasonable, like the "get_x_from_point" suggestion already made - that's a single verb (spread over several words), that is then applied to a point (as object). The "get" can be elided if the function name still makes sense... "x_from_y" is a pretty common idiom.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3033
Joined: Sat May 09, 2009 11:55 pm UTC

Re: Subject/Object/Verb ordering in code

Postby Qaanol » Mon Apr 13, 2015 9:38 pm UTC

What I would *really* like, is to have a language which “tags” the parameters, and allows the programmer to put them in any order. For example, the Officer class could define an arrest method like this:

void arrest(Person whom, Location where, Time when);

Or if defaults are desired, like this:
void arrest(Person whom = theUsualSuspect, Location where = thisOfficer.location, Time when = currentTime());

And then a call could look like any of the following:

officerKrupke.arrest(joe, timesSquare, now);
officerKrupke.arrest(whom=rasputin, where=theKremlin, when=atTheStrokeOfTwo);
officerKrupke.arrest(where=laguardia, when=midnight, whom=almonzoWilder);

If defaults values are provided, then any number of parameters can be omitted from the end, or by passing “void” for that parameter either in order or through the tag syntax.
wee free kings

User avatar
WanderingLinguist
Posts: 230
Joined: Tue May 22, 2012 5:14 pm UTC
Location: Seoul
Contact:

Re: Subject/Object/Verb ordering in code

Postby WanderingLinguist » Tue Apr 14, 2015 12:50 am UTC

Qaanol wrote:What I would *really* like, is to have a language which “tags” the parameters


Swift, Objective-C, C#, and Python all do that. Probably a few other languages, too. (And you can fake it in Javascript).

(edit: you can even sort of do it in C, if your compiler supports C99. See here.)

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3033
Joined: Sat May 09, 2009 11:55 pm UTC

Re: Subject/Object/Verb ordering in code

Postby Qaanol » Tue Apr 14, 2015 1:11 am UTC

WanderingLinguist wrote:
Qaanol wrote:What I would *really* like, is to have a language which “tags” the parameters


Swift, Objective-C, C#, and Python all do that. Probably a few other languages, too. (And you can fake it in Javascript).

(edit: you can even sort of do it in C, if your compiler supports C99. See here.)

I use Objective-C a lot, but it doesn’t let me rearrange the parameters at my leisure.
wee free kings

Derek
Posts: 2117
Joined: Wed Aug 18, 2010 4:15 am UTC

Re: Subject/Object/Verb ordering in code

Postby Derek » Tue Apr 14, 2015 1:50 am UTC

What I would like to see is a language that allows arbitrary currying. For all the praise that functional programming wankers give currying, I find it remarkable that none of them have ever wanted to curry parameters in the reverse order. You can do it in Python with some hacks, but it's far from typesafe.

User avatar
hotaru
Posts: 1017
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Subject/Object/Verb ordering in code

Postby hotaru » Tue Apr 14, 2015 2:06 am UTC

Derek wrote:What I would like to see is a language that allows arbitrary currying. For all the praise that functional programming wankers give currying, I find it remarkable that none of them have ever wanted to curry parameters in the reverse order.

isn't that exactly what flip is for in haskell?

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
ucim
Posts: 5373
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Subject/Object/Verb ordering in code

Postby ucim » Tue Apr 14, 2015 2:15 am UTC

Qaanol wrote:What I would *really* like, is to have a language which “tags” the parameters, and allows the programmer to put them in any order. For example, the Officer class could define an arrest method like this:

void arrest(Person whom, Location where, Time when);
I do this in php by passing an array to the function. It has the disadvantage that I have to pack up the array before calling the function, and then unpack it when the function is evaluated. But it has the advantages that I can add new parameters to the function at any time without breaking existing function calls, I can define defaults for any parameter (instead of just the last ones), and I can recover from most bad function calls from within the function.

$evidence = kill('victim'=>'Col. Mustard', 'weapon'=>'lead pipe');

Later, when I realize that I need to specify a location, I can rewrite the function to do something with the location (if it's there), and then the function call becomes:

$evidence = kill('victim'=>'Col. Mustard', 'weapon'=>'lead pipe', 'room'=>'Conservatory');

without breaking any of the other function calls.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Subject/Object/Verb ordering in code

Postby ahammel » Tue Apr 14, 2015 2:39 am UTC

hotaru wrote:
Derek wrote:What I would like to see is a language that allows arbitrary currying. For all the praise that functional programming wankers give currying, I find it remarkable that none of them have ever wanted to curry parameters in the reverse order.

isn't that exactly what flip is for in haskell?

Eh... rearranging a long parameter list using only flip is a good way to make your code unreadable.

You can fake named, order insensitive parameters with a data type and the curly-braces syntax, though.

Code: Select all

data Args = Args
    { person   :: String
    , officer  :: String
    , location :: String
    }

arrest :: Args -> String
arrest Args{..} =
    concat [ officer
           , " busted "
           , person
           , " in "
           , location
           ]

main = putStrLn . arrest
    $ Args { officer  = "Kripke"
           , location = "Times Square"
           , person   = "Joe"
           }
Wrote that on a phone, please don't be hilariously wrong
He/Him/His/Alex
God damn these electric sex pants!

User avatar
hotaru
Posts: 1017
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Subject/Object/Verb ordering in code

Postby hotaru » Tue Apr 14, 2015 3:43 am UTC

ahammel wrote:Eh... rearranging a long parameter list using only flip is a good way to make your code unreadable.

if you're using long parameter lists in haskell, you're doing something very wrong. wrong enough that searching for a->b->c->d->e->f->g->h->i on hoogle doesn't work.

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Subject/Object/Verb ordering in code

Postby ahammel » Tue Apr 14, 2015 3:46 am UTC

hotaru wrote:
ahammel wrote:Eh... rearranging a long parameter list using only flip is a good way to make your code unreadable.

if you're using long parameter lists in haskell, you're doing something very wrong. wrong enough that searching for a->b->c->d->e->f->g->h->i on hoogle doesn't work.

"Long" in the sense of "longer than two"
He/Him/His/Alex
God damn these electric sex pants!

User avatar
hotaru
Posts: 1017
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Subject/Object/Verb ordering in code

Postby hotaru » Tue Apr 14, 2015 4:03 am UTC

ahammel wrote:"Long" in the sense of "longer than two"

in that case, you might might need (flip .) in addition to flip... far from what i'd call unreadable.

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
WanderingLinguist
Posts: 230
Joined: Tue May 22, 2012 5:14 pm UTC
Location: Seoul
Contact:

Re: Subject/Object/Verb ordering in code

Postby WanderingLinguist » Tue Apr 14, 2015 6:12 am UTC

Qaanol wrote:
WanderingLinguist wrote:
Qaanol wrote:What I would *really* like, is to have a language which “tags” the parameters


Swift, Objective-C, C#, and Python all do that. Probably a few other languages, too. (And you can fake it in Javascript).

(edit: you can even sort of do it in C, if your compiler supports C99. See here.)

I use Objective-C a lot, but it doesn’t let me rearrange the parameters at my leisure.


Ah, true. Swift and Objective-C do require them in order.

Python, C#, Dart don't care about the order (you can use them pretty much just the way you wrote in your example). JavaScript also work just the way you wrote, if you don't mind the extra set of braces ;-)

Derek
Posts: 2117
Joined: Wed Aug 18, 2010 4:15 am UTC

Re: Subject/Object/Verb ordering in code

Postby Derek » Tue Apr 14, 2015 7:29 am UTC

hotaru wrote:
ahammel wrote:"Long" in the sense of "longer than two"

in that case, you might might need (flip .) in addition to flip... far from what i'd call unreadable.

I would call that pretty unreadable. In fact, I would call a single flip pretty dirty. The point of currying is that it's "free", if I have to start manipulating my function for each specific order I might want to curry, that's not free anymore.

User avatar
phlip
Restorer of Worlds
Posts: 7538
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Subject/Object/Verb ordering in code

Postby phlip » Tue Apr 14, 2015 7:56 am UTC

ahammel wrote:Eh... rearranging a long parameter list using only flip is a good way to make your code unreadable.

What, don't you like bubble-sorting your parameters?

Code: Select all

shellgame = flip . (flip.) . ((flip.).) . flip

f a b c d = (a,b,c,d)
main = print $ shellgame f 1 2 3 4 -- prints (3,2,4,1)

[edit] Oh, hello a lot of extra posts. That'll teach me to click "Post Reply" in a tab I've had open all day...

[edit 2] Though now that I think about it, that (flip.) syntax is itself a form of parameterised currying... so something like (/2) is partially-applying the division function on the second parameter. And you can go (`f` x) to partially-apply any (named) function on the second parameter, equivalent to (flip f x). Still not arbitrary partial application, but it's not nothing...

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 5 guests