News for hackers. Stuff that matters.
Re:Verb-Noun vs. Noun-Verb by thomascgalvin on Wednesday October 16, 2019 @02:44PM (#21273911)
> Something I noticed at the time was that the syntax for functional languages tends to be verb then noun: f(x), whereas the syntax for object oriented languages tends to be noun then verb: x.f().... There's a big difference in usability though: auto-complete.

Auto-complete also really helps with discoverability. Consider checking for the presence of a key in a map/dictionary. In Java, auto-complete will quickly lead you to `map.containskey(key)`. In Python, though, you'd have to know that the syntax is `if value in dict`.

Now, let's check for the presence of a value. Auto-complete again quickly leads you to `map.containsValue(value)`. In Python, Google tells me that it's `if value in dict.values()`, which seems more difficult to stumble upon.

And that's for a built-in data structure. A lot of my job involves trudging through other people's code, trying to figure out how they architect their ball of cats. Auto-complete is a great tool for that; it lets you quickly and easily poke around, and see what the various nouns in the system can do.

Re:Verb-Noun vs. Noun-Verb by karmakaze on Wednesday October 16, 2019 @02:52PM (#21273992)
Actually FP is more often verb-verb as in compose these verby thing together in this way to make a new verb then finally give it a starting noun.
Re:Verb-Noun vs. Noun-Verb by DanielBMarkham on Wednesday October 16, 2019 @04:27PM (#21275148)
This is an important point. When done well, in FP the data "disappears", i.e. the types control flow and the functions talk about what you're doing. So there's no "find me what I c an do with this object" instead it's "What am I returning?" It sounds the same but it isn't.

Yes, way in the heart of a functional program there's some code sorting lists of ints or something. But by that time, it's all labeled to the point where the functions just tell you what happens. As someone browsing the source, the nouns disappear.

Re:Verb-Noun vs. Noun-Verb by thomascgalvin on Wednesday October 16, 2019 @03:03PM (#21274125)
One of the things I like about Java's streams is that it makes the verb-chaining more obvious, at least to me.

list.stream().filter().mapToInt().sum() just reads better to me than sum( mapToInt( filter(list) ) )

Re:Verb-Noun vs. Noun-Verb by Garph on Wednesday October 16, 2019 @08:57PM (#21277922)
I don't enjoy balancing parentheses in Python so I tried to bring Clojure's threading macro into the language...

  def do(x, fs):
      for f in fs:
          x = f(x)
      return x
Which allows left-to-right style programming

  do(list, filter, partial(map, int), sum)
I haven't put this into production code yet, but love pipelining scripts with do
Re:Verb-Noun vs. Noun-Verb by sooheon on Thursday October 17, 2019 @12:33AM (#21278940)
Also see PyToolz's implementation: https://toolz.readthedocs.io/en/latest/api.html#toolz.functo...

They differentiate thread first/last for Fns with arity > 1, just like Clojure.

Re:Verb-Noun vs. Noun-Verb by karmakaze on Wednesday October 16, 2019 @09:09PM (#21277990)
I made a thing[0] just like that to do pipelined async db queries:

  CompletableFuture<Member> asyncProjectMembers =
    Async.pipeline(Accounts.where("id >= ?", 1000);,
                   (accounts) -> accounts.loadProjects("updated_at >= ?", Instant.now().minusDays(30)),
                   (projects) -> projects.loadMembers());
If you assign the intermediates to variables, each instance will have associated with it the related collection that's queried while avoiding N+1's.

[0] https://github.com/karmakaze/safeql

Re:Verb-Noun vs. Noun-Verb by greggman2 on Thursday October 17, 2019 @12:29AM (#21278918)
I know most will disagree but I find code the above hard to read. I'd much prefer

    const people = list.stream();
    const peopleOlderThan50 = people.filter(??);
    const average = peopleOlderThan50.mapToInt().sum() / peopleOlderThan50.length;
Or some such thing. The more complex the chain the harder it is for me to read. Does anyone else have that experience?
Re:Verb-Noun vs. Noun-Verb by sooheon on Thursday October 17, 2019 @02:41AM (#21279490)
There's a spectrum here. Someone even more explicit than you may insist that `average` should be split up into explicit bindings for the mapping to Int, the sum, and the count.

Also, for non-toy examples, there are real benefits to composing transformations, so that you don't pay the memory and performance costs of assigning intermediate sequences.

Re:Verb-Noun vs. Noun-Verb by ThrowawayR2 on Saturday October 19, 2019 @08:35AM (#21298143)
You're not alone; those long chains are annoying to decipher. The other benefit of what you wrote is that if you have to track down a bug in the chain, you can actually examine the intermediate variables directly instead of having to pick apart a long chain so that a variable is exposed for you to look at in the debugger.
Re:Verb-Noun vs. Noun-Verb by joostdevries on Thursday October 17, 2019 @02:18AM (#21279400)
I agree. Naming parts of your code is important. An alternative to named local vals is to either use named functions instead of lambdas: people.filter(olderThan50) or (I use Kotlin) use named extension functions: people.countOlderThan50()
Re:Verb-Noun vs. Noun-Verb by splittingTimes on Thursday October 17, 2019 @04:40AM (#21280048)
In any nontrivial application, doing this for many of your types, does this not bloat your API considerably, which adds to the cognitive load?
Re:Verb-Noun vs. Noun-Verb by rtkwe on Wednesday October 16, 2019 @03:49PM (#21274691)
Yeah I much prefer that style because it reads left to right like I naturally read as an English speaker. It flows more naturally from the original object and the changes applied to it.
Re:Verb-Noun vs. Noun-Verb by Twisol on Wednesday October 16, 2019 @04:11PM (#21274949)
Agreed. Some functional languages (like F#) have a pipelining operator |> that gives the same syntactic impression:

    list |> map (1+) |> filter odd |> sum
Re:Verb-Noun vs. Noun-Verb by the_gipsy on Wednesday October 16, 2019 @06:53PM (#21276898)
I have found myself using pipes many times in Elm, because they make the code so much more readable. Now I understand why!

I haven't seen an autocomplete that works on pipes. But with a good type system, it is technically possible to list all compatible functions that take "noun" as first parameter.

Sometimes you supply partially applied functions (also with pipes in noun->verb order) and that's not so easy to match:

noun |> verb1 |> (otherNoun >> verb2) |> etc

But perhaps even functions that take "noun" as nth parameter could be suggested.

Re:Verb-Noun vs. Noun-Verb by codr7 on Wednesday October 16, 2019 @06:36PM (#21276756)
And other languages, such as Forth; don't need one.

    list map filter odd sum
Re:Verb-Noun vs. Noun-Verb by Twisol on Thursday October 17, 2019 @12:04AM (#21278818)
Huh. I would've expected it to be `odd filter`, not `filter odd`.
Re:Verb-Noun vs. Noun-Verb by zwaps on Thursday October 17, 2019 @02:30AM (#21279438)
Interestingly enough, the now standard data manipulation package in R, dplyr, uses pipelines.
Re:Verb-Noun vs. Noun-Verb by karmakaze on Sunday October 20, 2019 @12:32PM (#21305162)
Good to learn me some F#, looks like Elixir.
Re:Verb-Noun vs. Noun-Verb by jodrellblank on Wednesday October 16, 2019 @04:21PM (#21275079)
If verbs from the object flowing you want, "That style to me is preferable" you should say. (Style is the object, preferring it is the verb)

English reads left to right overall, but writing instructions in English does not flow smoothly either way. e.g. "shuffle a deck of playing cards then deal four" reads more naturally than either "a deck of playing cards shuffle then four cards deal" or "deal four cards after shuffling a deck of playing cards".

shuffle(cards).deal(4) is a mix of both approaches.

Re:Verb-Noun vs. Noun-Verb by rtkwe on Wednesday October 16, 2019 @04:35PM (#21275250)
Yes yes, english doesn't follow this noun-verb order but that's not what I'm actually talking about.

Usually the languages either encourage cards.shuffle().deal(4) or deal(shuffle(cards),4).

In the 'noun-verb'/OOP version the sequence of modifications follows the english reading order where basically I only have to keep information about the last result in my head. The functional verb-noun version I have to pop in and out of layers: 'ok we're dealing what?, something shuffled, what are we shuffling?, the cards object/variable, ok we're dealing shuffled cards how many are we dealing? 4.'

In general the noun-verb follows the sequence of operations applied by the computer so it's easier to read.

Re:Verb-Noun vs. Noun-Verb by jodrellblank on Wednesday October 16, 2019 @04:48PM (#21275444)
That's where I was going as well, LISP style and APL style claims "reads left to right" but having to build up a stack of buffered work which you can only unwind once you get to the end, is annoying and unhelpful and limiting.

But simply turning it around to cards.shuffle().deal(4) isn't a good answer, it's still the case that you can only put a small number of things together in a chain because it stops making sense. If the next move was to start the game, "cards.shuffle().deal(4).startgame('some-card-game')" does not make sense because starting the game is not something the cards do, but "start(deal(shuffle(cards), 4), 'some-card-game')" can make sense because start is a function which takes a board state and a game to start. It describes the world state, not the cards and their abilities.

That is, neither style is right, but a mixed style where both approaches are available and you can mix and match to be more expressive, works much better, IMO. Chunking a small number of things with prefix into one operation, or with postfix into one operation, but combining those chunks flexibly at a larger scale.

Re:Verb-Noun vs. Noun-Verb by cb504 on Wednesday October 16, 2019 @05:06PM (#21275703)
the main point was about auto-completion and usability and discoverability. fluent api for the win.
Re:Verb-Noun vs. Noun-Verb by qtplatypus on Wednesday October 16, 2019 @10:23PM (#21278373)
English is worse as it is SVO. So a more English like language would be all infix operators. I thunk part of ambiguity is that English can be used in both modes.

“Say that” “He said”

Re:Verb-Noun vs. Noun-Verb by rtkwe on Wednesday October 16, 2019 @11:58PM (#21278789)
I was really just talking about the left to right order of modification not the actual order of English sentences. Apparently I was very unclear because that's all the responses I'm getting.
Re:Verb-Noun vs. Noun-Verb by iameli on Thursday October 17, 2019 @01:43AM (#21279226)
Yeah, Lisp-y parenthesis syntax isn't the best for that, but Ruby and CoffeeScript express it reasonably well: `sum mapToInt filter list`
Re:Verb-Noun vs. Noun-Verb by rtkwe on Wednesday October 16, 2019 @03:06PM (#21274154)
Which is basically just a sequence of verb-nouns.
Re:Verb-Noun vs. Noun-Verb by kerkeslager on Wednesday October 16, 2019 @05:43PM (#21276180)
> Auto-complete also really helps with discoverability. Consider checking for the presence of a key in a map/dictionary. In Java, auto-complete will quickly lead you to `map.containskey(key)`. In Python, though, you'd have to know that the syntax is `if value in dict`.

This isn't an argument for noun-verb over verb-noun, though it's an argument for more homogeneous syntax. `if value in dict` isn't noun-verb OR verb-noun.

There's not really a reason that f(<tab> couldn't complete with arguments (and it does in many systems). I think if you wanted to use autocomplete to make a point, you'd have to argue that it's more effective somehow to complete on verbs than on nouns.

Re:Verb-Noun vs. Noun-Verb by saagarjha on Wednesday October 16, 2019 @02:51PM (#21273978)
I also think that the object-oriented syntax matches my thinking process more closely: for example, I have an array of strings, and I want to convert them to numbers, pick only the odd ones then sum them rather than "I want to sum some things…things which I'm filtering by parity…which are actually strings I'm converting to integers".
Re:Verb-Noun vs. Noun-Verb by scarejunba on Wednesday October 16, 2019 @03:16PM (#21274277)
That's how the thread-last/first macros help in Clojure. You sort of specify a pipeline:

``` (-> list parseInt isOdd sum) ```

Is the same as

``` (sum(isOdd(parseInt(list))) ```

Particularly useful if you're pulling a deeply nested key out.

Re:Verb-Noun vs. Noun-Verb by Twisol on Wednesday October 16, 2019 @04:07PM (#21274896)
I think that can be solved without bringing objects into the mix -- functions are usually grouped up into modules of some kind, so leading with `Foo.` (or `foo::` in C++, etc.) still provides a useful level of scoping that can aid autocomplete.

On the other hand, tools like Hoogle [0] let you search for functions based on type, so you can search for e.g. `ByteString -> _` to find functions that take a bytestring. There's no reason the same paradigm can't be applied in an IDE.

Re:Verb-Noun vs. Noun-Verb by dyarosla on Wednesday October 16, 2019 @02:55PM (#21274037)
+1 for “ball of cats”. That’s a new one for me.
Re:Verb-Noun vs. Noun-Verb by delusional on Wednesday October 16, 2019 @05:43PM (#21276179)
It's real great to know that I can get and set all the fields. Thanks previous programmer.
Re:Verb-Noun vs. Noun-Verb by AmpsterMan on Wednesday October 16, 2019 @09:10PM (#21277995)
This is one of those paradigms that I don't understand in Java. It's the most trivial of trivial encapsulations.
Re:Verb-Noun vs. Noun-Verb by Izkata on Friday October 18, 2019 @05:14PM (#21295143)
It is (was?) the primary way to maintain binary compatibility between versions of class files, where switching an attribute to a method (if logic such as verification needed to be added in a future version) would break that compatibility.
Re:Verb-Noun vs. Noun-Verb by mthoms on Thursday October 17, 2019 @11:24AM (#21283030)
Setters I get (see what I did there?). It's the superfluous getters that simply return the values I'll never understand.
Re:Verb-Noun vs. Noun-Verb by Izkata on Friday October 18, 2019 @05:18PM (#21295166)
See my cousin comment - it maintains compatibility when changes are internal to the class. For example, if a field was switched from concrete to derived, you'd have to switch the attribute to a getter, which would break compatibility with the previous version.
Re:Verb-Noun vs. Noun-Verb by bobbyi_settv on Thursday October 17, 2019 @01:50AM (#21279265)
But exactly because it's easier to "stumble upon" the right answer, I think this may be worse for games. I like feeling as if it's necessary to come up with the solution in my head and then do it. It's not satisfying if every puzzle can be quickly solved by selecting each item in the room and trying the couple actions the game offers you for that item.
Re:Verb-Noun vs. Noun-Verb by stouset on Wednesday October 16, 2019 @05:23PM (#21275919)
The Python approach also exposes unnecessary details and by doing so causes a performance hit by forcing you to get a list of keys/values and then find out of what you’re looking for is in them. This is slower than what the dictionary could do internally: hash the key and check if there’s an entry for it in the backing store.
Re:Verb-Noun vs. Noun-Verb by klodolph on Wednesday October 16, 2019 @05:27PM (#21275957)
The .values() method does not return a list, it returns a view object. If you write ‘value in m.values()’, it invokes the __contains__() method.

(Note that this cant be a hash check because it’s not testing the presence of a key.)

(Also note that the story is different if you look at sufficiently archaic versions of Python.)

Re:Verb-Noun vs. Noun-Verb by cortesoft on Thursday October 17, 2019 @12:22AM (#21278887)
This is one of the reasons I like ruby better than python... none of the magic 'dunder' methods... if you want to define a custom adder for your class, so "foo + bar" works, you do "def +()" in ruby instead of "def __add__ ()" in Python.... I love that ruby just uses the actual operator instead of some arbitrary method name you have to remember.
Re:Verb-Noun vs. Noun-Verb by lifthrasiir on Thursday October 17, 2019 @03:15AM (#21279644)
> none of the magic 'dunder' methods

Ruby do have equivalents to Python magic methods... disguised as normal methods. For example Python `__hash__` is Ruby `hash` and both are used by built-in dict/hash values and you should be aware of that fact in both. There are some philosophical differences as well, Python likes to have standalone functions that are customized via magic methods (e.g. `str` vs. `__str__`, you don't normally call the latter) and in Ruby everything is method (e.g. `to_s`). It really seems like a matter of taste.

Re:Verb-Noun vs. Noun-Verb by stouset on Wednesday October 16, 2019 @05:29PM (#21276002)
Fair enough!