Ticket #1525 (closed bug: wontfix)

Opened 5 years ago

Last modified 5 years ago

Node adding is magical, modifies in-place when you'd think it wouldn't

Reported by: jabapyth Owned by: apoirier
Priority: major Component: uncategorized
Version: 0.4.1 Keywords: magic
Cc:

Description

This is a design decision, and there's no accounting for taste ;) but I would highly suggest *not* using "<<" to modify your node tree. People expect "<<" to return a new object, not modify one of the objects in place. I would recommend changing to magicify the "<<=" operator, which shows the casual observer that you are modifying the object on the left-hand-side.

Thanks!

Change History

comment:1 in reply to: ↑ description Changed 5 years ago by apoirier

  • Status changed from new to closed
  • Resolution set to wontfix

Replying to jabapyth:

This is a design decision, and there's no accounting for taste ;) but I would highly suggest *not* using "<<" to modify your node tree. People expect "<<" to return a new object, not modify one of the objects in place. I would recommend changing to magicify the "<<=" operator, which shows the casual observer that you are modifying the object on the left-hand-side.

Thanks!

When choosing the operator to overload, I indeed considered the += or <<= operator but the big problem is they can't be chained, raising a SyntaxError exception:

with h.form:
    h <<= 'First name: ' <<= h.input

which is a very handy with << instead.

Also I must admit changing a bit the semantic of << didn't disturb me a lot with my Unix shell and C++ background (cout << "hello" << endl) where, for streams, << is officially not the "left shift" but the "insertion" one ;)

Then, if you want a pure LISP-ish no side-effects tree creation, Nagare also supports the syntax:

h.div(
    h.div(
        h.p('hello'),
        h.p('world')
    )
)

Best regards

Note: See TracTickets for help on using tickets.