[squeak-dev] String>expandMacros rules?
hannes.hirzel at gmail.com
Tue Mar 7 10:44:23 UTC 2017
On 3/6/17, tim Rowledge <tim at rowledge.org> wrote:
> [removing some mangled quote-misattribution that doesn’t really matter ]
>>>> ‘%-0.1e’ printf: x
>>>> is a whole lot nicer than
>>>> (x printShowingDecimalPlaces: 1) padded: #left to: 1 with: $0
>>> I would really say the other way round.
>>> Really, frist is faster to write, but second is easier to read.
>>> I don't have to memorize what character means left or right padding, what
>>> number means precision and what means overall length and such.
>>> I think the first one is trying too hard (why, yes, C, I am looking at
>> My thoughts exactly!
> Well there’s two parts to this
> a) the ability to neatly format output for printing/displaying in
> textmorphs/writing to CSV or similar files/transmitting across messaging
Yes, this is a definite need. Thanks, Tim that you works on this.
> b) the precise syntax used
A matter of discussion....
> It’s useful to be able to get a Float to print in a suitable format with
> alignment, precision, padding or whatever. Same with other numbers.
To have a consistent solution for numbers is a need.
> We have
> quite a lot of code scattered about that does various parts of it with
> varying degrees of niceness. It would be nice to get it nicely aligned so
> that it is findable without spending too much time.
> If the best way to do that is with
> Float>printInMaxWidth:withDecimalPlaces:aligned:paddingChar:etc:etc: then
> fine; it’s better than the current situation.
Surely a good first step and you will probably have no objections from
anybody for this.
> Then to simplify life we’d
> probably want versions that assume default width, or precision, or padding
> and so on, so now you have more messages to know about. Then someone will
> want a simple spec language to encode the format. And we re-invent the C
> format in all but name and possibly incompletely anyway.
Yes, this is an issue.
> At a total cost of 53 methods across 10 classes (including unit tests) to
> provide a neat and simple and flexible formatter - even if you don’t like
> the specific spec language details - this is a pretty good deal.
I do not understand what you mean with the last paragraph. To what do
the 53 methods refer to?
However going for a well known existing formatting language is surely
a good thing. Even if you do not like the particular syntax.
" The format string is written in a simple template language, and
specifies a method for rendering an arbitrary number of varied data
type parameters into a string"
The list here
has 27 languages implementing the small printf DSL.
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> The problem with the gene pool is that there is no lifeguard.
More information about the Squeak-dev