Launched: Reuse logic and create nested loops with the new WithName() formula

Already redid one of my formulas with this and it worked like a charm. Thanks Coda!

Hi @shishir,

First of all, I <3 Coda and am so thankful you made such a great platform. I’ve built business tools on top of Coda that go far beyond what some commercial off-the-shelf products can do. It’s incredible!

That being said (and I realize this may sound pedantic), the current syntax of WithName is a minor but consistent annoyance. When I use it many times within a complicated formula, it can make the whole thing very hard to read and follow along, as well as make the auto-indenter useless. I understand the issue you mentioned with formula editor order / auto complete as well as mid-expression var-args being outside of your parser’s design. However, have you considered transforming the formula editor before processing? I am unaware of how things work under the hood, so I could be wrong, but could you rewrite a new formula WithNames(xN,xS,yN,yS,E) behind the scenes (before general parsing) to match your current syntax of WithName(xS,xN,WithName(yS,yN,E))?

There are three issues I see:

  1. The overuse of parens and the need to balance them, rendering the auto-indenter useless.
  2. Brevity and clarify.
  3. I feel strongly that names should be first. This is much easier to work with. In pretty much all programming languages you write x = blah blah blah, not blah blah blah → X. The reason for this is that 1) variable names are shorter and easier to alight vertically, and 2) it makes it easier to find what the definition of a variable is. I’m guessing you did it this way so someone could write [value].WithName([var], [expression]), so maybe this was unavoidable.

Here is my suggestion:

WithNames(
  name1, s1,
  name2, s2,
  expr)

rather than either:
WithNames(s1, name1, s2, name2, expr)
or the current:
WithName(s1, name1, WithName(s2, name2, expr))

On a non-sequitur, my other biggest annoyance is that If([x].IsBlank(),"blah",[x].[column]) in a canvas formula returns an error rather than "blah" when [x] is blank. This requires annoying workarounds like using a one-row table. I’m surprised Coda hasn’t implemented short-circuiting.

3 Likes

+1 I agree, it’s inconvenient.

1 Like

I don’t agree or disagree, but I think it is sort of a non-issue. Any programming language has it’s own somewhat peculiar things - and this one really isn’t that bad.
I try to format my CFL in such a way that I can easily see the stucture of my (more complicated) CFL. I have triple or quadripple nested WithNames’ and honestley, I think it is very readable.
The following looks nice ‘on paper’:
WithNames(
name1, s1,
name2, s2,
expr)
but with ‘real code’ that stretches over multiple lines in the editor, the current structure might be easier to recognize than this.

If @Coda_hq wants to honor this, the function needs a new name in order to not break existing code. The suggestion to put the name of the WithName variable first intuitively makes sense to me though.

That was one of the hardest things to find in coda :exploding_head:

I’ve spent hours and hours searching for the solution of CurrentValue being overriden only to learn there’s WithName :tears-of-joy:

2 Likes