On Mon, 08 Oct 2007 16:56:11 -0700, William J. wrote:
That’s a violation of common sense. ‘%!PS-Adobe’ isn’t going
to change, and therefore 10 won’t need changing.
But magic numbers suck.
On Mon, 08 Oct 2007 16:56:11 -0700, William J. wrote:
That’s a violation of common sense. ‘%!PS-Adobe’ isn’t going
to change, and therefore 10 won’t need changing.
But magic numbers suck.
Hi –
On Tue, 9 Oct 2007, William J. wrote:
Furthermore, why say “.length” when you can say “.size”?
For some reasons, I like #length for strings and #size for arrays.
I’m not worried about the two extra characters. I guess I’m profligate
with electrons 
David
On Tue, 9 Oct 2007 21:19:42 +0900, Daniel B. wrote:
That would only be true if vendors randomly and unexpectedly changed
them. From what I can gather (from Wikipedia and general experience) as
formats change vendors may extra add data to the end of the magic number
(or create a new one), but always leave the ‘base’ magic number alone.Personally, I think you should stop worrying and learn to love the magic
number.
No, not the magic(5) kind of magic number…
I don’t think
“%!PS-Adobe”
is changing either. And if it’s not changing, then its length will
always
be 10.
I’m talking about what wikipedia calls an “unnamed numerical constant”.
It
took me a few seconds to realize that “10” was the length of
“%!PS-Adobe”.
Is PS.length (or size, if you prefer) longer to type? Yes. Is it
likely
to change? No. Is it more explanatory? Yes. Will it still work when
you
copy and paste this code to search for a different magic phrase? Yes.
Jay L. wrote:
On Mon, 08 Oct 2007 16:56:11 -0700, William J. wrote:
That’s a violation of common sense. ‘%!PS-Adobe’ isn’t going
to change, and therefore 10 won’t need changing.But magic numbers suck.
That would only be true if vendors randomly and unexpectedly changed
them. From what I can gather (from Wikipedia and general experience) as
formats change vendors may extra add data to the end of the magic number
(or create a new one), but always leave the ‘base’ magic number alone.
Personally, I think you should stop worrying and learn to love the magic
number. 
Regards,
Dan
From: “Jay L.” [email protected]
I’m talking about what wikipedia calls an “unnamed numerical constant”. It
took me a few seconds to realize that “10” was the length of “%!PS-Adobe”.
Is PS.length (or size, if you prefer) longer to type? Yes. Is it likely
to change? No. Is it more explanatory? Yes. Will it still work when you
copy and paste this code to search for a different magic phrase? Yes.
Agreed 100%
From a readability standpoint I’d put it in the same category as
using, say, 90 instead of ?Z.
Or using 1246774599 instead of ‘JPEG’.unpack(“N”).
The number of characters typed (golfing aside) shouldn’t even enter
into consideration in cases like these.
Regards,
Bill
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs