[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Re: string formatting notation



These add little or nothing new

I would argue it adds readability and clarity, and reflects the naturalness of the string formatting operation. Not only fewer characters, but also one less pair of parens, or in the array case swapping parens for brackets, which is easier to visually parse. The general problem is that string formatting and interpolation are very uncomfortable in SC. Your options are:

- postf, for which you will almost always forget the necessary ending \n
- interpolating ++s, which is 10 extra characters (" ++ and ++ "), 6 of them symbols, which breaks apart the string and makes it difficult to understand the message being constructed
- format, which means you are probably avoiding postf and placing the formatted string within postln. Then you end up with:

postln("Why is % afraid of %?".format(6, 12))

Or something similar that is in my experience noisy and makes you really wish the token came at the end so you could just write:

postln("The answer is " ++ answer)

In my time using SC I have never felt comfortable formatting strings. Other languages do this much better, and rightly so because it is an extremely necessary and frequent task. Cf Swift's "My \(var).", and PHP's "My $var." and Ruby's "My #{var}." I am presenting this as one possible (easy) solution to that problem. I think genuine, simple string interpolation would also be valuable, even more valuable than what I'm suggesting to be honest. In Swift I actually prefer typing "End of \(message)" because the string interpolation notation is so clean visually.

> If the issue is that you don't want type "format," two rejoinders:

I hope I make it clear in the above response that it isn't typing that's a problem, it's that the design of format in this language feels bad and looks bad, and there are viable alternatives that have worked well in other languages. This is primarily a readability concern. Descriptive/lengthy method names definitely are worth it for many operations, but I also feel that having to read another word for a very common operation adds unwanted noise. How is this different from using ++ over (fictional) ".concat"?

> make SC harder to learn

Fair. although parallelism with Python 2 helps I would think.

> violate existing conventions

I think anything new would have to do that, right? I do not see what convention this violates, unless it's the general one of "there is another method." + and ++ are also symbolic String operators.

> and bloat the method table unnecessarily.

I fail to see how this is a concern at all. Maybe 8-16 extra bytes? No new selector symbol added. The dispatch itself is constant time.

On Fri, Dec 22, 2017 at 3:05 AM <jamshark70@xxxxxx> wrote:
Scott Wilson-3 wrote
> Sorry, I’m opposed to both. There’s way too many duplicate methods in SC
> added to support personal preference of developers.
>
> These add little or nothing new, make SC harder to learn, violate existing
> conventions and bloat the method table unnecessarily.

I am 200% in agreement with Scott here.

I'll add one more reason: the longer I do this, the more strongly I feel
that code written for legibility is easier to maintain than code written to
save keystrokes. I have a repetitive strain injury but longer, descriptive
variable and method names are worth the effort so that I and others can make
sense of my code.

If the issue is that you don't want type "format," two rejoinders:

1. The IDE autocompletes String methods quite assertively if it can see that
the receiver is a string literal. "A string".for should present autocomplete
options.

2. If that's still objectionable, use a snippets facility, e.g.
Quarks.install("ddwSnippets").

That is, if it's a typing problem, solve it by automating some of the
typing.

hjh



--
Sent from: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SuperCollider-Users-New-Use-this-f2676391.html

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/