3 ms·
Same way that you use any other API: by reading the docs. This is at least a very common pattern; it's highly likely that whoever maintains this code will have
by nostrademons 10y ago
Same way that you use any other API: by reading the docs. This is at least a very common pattern; it's highly likely that whoever maintains this code will have seen it before. And if you're using an IDE, the IDE will even tell you this as you hit '.'
BTW, it doesn't have to be the same object: if memory is abundant and CPU is not, it can often make sense to create a fresh object with each call. Doing this lets you share partially-constructed objects without worrying that mutation will result in surprising effects:
let box = NewCanvas()
.DrawLine(50, 0)
.DrawLine(50, 50)
.DrawLine(0, 50)
.DrawLine(0, 0)
let scene = [
box.Fill(Color.RED).TranslateTo(200,300),
box.Fill(Color.BLUE).TranslateTo(100, 300),
box.Fill(Color.GREEN).TranslateTo(400, 500)
]
scene.forEach(box => box.Draw())
- golergka 10y ago> Same way that you use any other API: by reading the docs. Best APIs are written in such an obvious way that you don't need to read the docs to read the code and understand what's happening.
- nostrademons 10y agoThat doesn't apply to any of the code examples posted so far in this thread: they would all require documentation about side-effects, shared state, immediate vs. delayed effects, etc.