3 ms·
I agree. You often get multi-line statements and in many languages/APIs they're a nature way of doing things. Here's an example (in no particular language):
by cabalamat 18y ago
I agree. You often get multi-line statements and in many languages/APIs they're a nature way of doing things. Here's an example (in no particular language):
win = Window.new()
.setTitle("A new window")
.setForeground(Red)
.setBackground(White)
.setMenuBar(fileMenu, viewMenu, helpMenu);
I think this would be uglier and more error-prone if instead you had to use \ or some other character to indicate they are all part of the same expression:
win = Window.new()\
.setTitle("A new window")\
.setForeground(Red)\
.setBackground(White)\
.setMenuBar(fileMenu, viewMenu, helpMenu);
- timknauf 18y agoInteresting. I hadn't come across that idiom before. In Python, you'll have things like: myLongList = [1, 2, 3, 4, 5, 6, 7, 8, 9] No continuation character is needed, because the continuation is implied. However, I can't think of a direct parallel to your example above. It looks handy. What API/language are you alluding to? I guess the Pythonic way would be something like: win = Window(title = "A new window", foreground = "Red", background = "White", menuBar = [fileMenu, viewMenu, helpMenu]) But I disgress. :^)
- deleted 18y ago[deleted]
- sc 18y agoJavaScript can just as easily attain this way of using named parameters: win = Window.new({title: "A new window", foreground: Red, background: White, menuBar: [fileMenu, viewMenu, helpMenu]});
- cabalamat 18y agoWhat API/language are you alluding to? As i said before: no particular language.
- sc 18y agoThe dot notation itself indicates continuation: win = new Window(). setTitle("A new window"). setForeground(Red). setBackground(White). setMenuBar(fileMenu, viewMenu, helpMenu);