I have a theory that strlen is bad.
1. The function itself is completly redundant, since it is a direct alias for sizeof. The language is simpler and faster to learn without strlen. (Although not by much.) 2. We'd like things in Pike to be as general as possible, e.g. + should add any kind of ADT, not just integers. Hence it is bad to make specializations of general functions. 3. As a specialization strlen is flawed, since it accepts nonstring arguments. 4. strlen provides a "transition aid" for C programmers, who can still write strlen and get a somewhat expected result. This advantage is however consumed by the implication that since Pike has strlen and sizeof, and strlen works as in C, sizeof would also work as in C.
Proposed course of actions:
1. Document strlen as deprecated. 2. Replace all strlen instances in Pike with sizeof.
C programmers might have odd ideas about treating strlen as an O(n) operation too. :-)
/ Johan Sundström (a hugging punishment!)
Previous text:
2003-01-20 17:02: Subject: Death to strlen! Death to the demoness Allegra Geller!
I have a theory that strlen is bad.
- The function itself is completly redundant, since it is a direct
alias for sizeof. The language is simpler and faster to learn without strlen. (Although not by much.) 2. We'd like things in Pike to be as general as possible, e.g. + should add any kind of ADT, not just integers. Hence it is bad to make specializations of general functions. 3. As a specialization strlen is flawed, since it accepts nonstring arguments. 4. strlen provides a "transition aid" for C programmers, who can still write strlen and get a somewhat expected result. This advantage is however consumed by the implication that since Pike has strlen and sizeof, and strlen works as in C, sizeof would also work as in C.
Proposed course of actions:
- Document strlen as deprecated.
- Replace all strlen instances in Pike with sizeof.
/ Martin Nilsson (Åskblod)
No argument here.
/ Peter Bortas
Previous text:
2003-01-20 17:02: Subject: Death to strlen! Death to the demoness Allegra Geller!
I have a theory that strlen is bad.
- The function itself is completly redundant, since it is a direct
alias for sizeof. The language is simpler and faster to learn without strlen. (Although not by much.) 2. We'd like things in Pike to be as general as possible, e.g. + should add any kind of ADT, not just integers. Hence it is bad to make specializations of general functions. 3. As a specialization strlen is flawed, since it accepts nonstring arguments. 4. strlen provides a "transition aid" for C programmers, who can still write strlen and get a somewhat expected result. This advantage is however consumed by the implication that since Pike has strlen and sizeof, and strlen works as in C, sizeof would also work as in C.
Proposed course of actions:
- Document strlen as deprecated.
- Replace all strlen instances in Pike with sizeof.
/ Martin Nilsson (Åskblod)
sizeof is also bad, the function should be called "size", "len" or "length".
/ Fredrik (Naranek) Hubinette (Real Build Master)
Previous text:
2003-01-20 17:02: Subject: Death to strlen! Death to the demoness Allegra Geller!
I have a theory that strlen is bad.
- The function itself is completly redundant, since it is a direct
alias for sizeof. The language is simpler and faster to learn without strlen. (Although not by much.) 2. We'd like things in Pike to be as general as possible, e.g. + should add any kind of ADT, not just integers. Hence it is bad to make specializations of general functions. 3. As a specialization strlen is flawed, since it accepts nonstring arguments. 4. strlen provides a "transition aid" for C programmers, who can still write strlen and get a somewhat expected result. This advantage is however consumed by the implication that since Pike has strlen and sizeof, and strlen works as in C, sizeof would also work as in C.
Proposed course of actions:
- Document strlen as deprecated.
- Replace all strlen instances in Pike with sizeof.
/ Martin Nilsson (Åskblod)
nelems :-)
Jag håller med. size() är mycket bättre.
/ Mirar
Previous text:
2003-01-21 09:41: Subject: Death to strlen! Death to the demoness Allegra Geller!
sizeof is also bad, the function should be called "size", "len" or "length".
/ Fredrik (Naranek) Hubinette (Real Build Master)
2 - I don't think a recursive method would be logical. I.e think of another example: ({ "123, "456" }) => 6? 8? That wouldn't make sense.
/ David Hedbor
Previous text:
2003-01-21 22:46: Subject: Death to strlen! Death to the demoness Allegra Geller!
But is nelems(x) for x=({ 1, ({ 2, 3 }) }) two or three?
/ Martin Nilsson (Åskblod)
BTW, count is a better name for it, IMHO.
/ Peter Lundqvist (disjunkt)
Previous text:
2003-01-21 22:58: Subject: Death to strlen! Death to the demoness Allegra Geller!
2 - I don't think a recursive method would be logical. I.e think of another example: ({ "123, "456" }) => 6? 8? That wouldn't make sense.
/ David Hedbor
I'd like count to count specific things in a structure, not just everything. @seealso @[String.count]
/ Martin Nilsson (Åskblod)
Previous text:
2003-01-21 23:00: Subject: Death to strlen! Death to the demoness Allegra Geller!
BTW, count is a better name for it, IMHO.
/ Peter Lundqvist (disjunkt)
How would that differ from sizeof?
/ Peter Lundqvist (disjunkt)
Previous text:
2003-01-21 23:02: Subject: Death to strlen! Death to the demoness Allegra Geller!
I'd like count to count specific things in a structure, not just everything. @seealso @[String.count]
/ Martin Nilsson (Åskblod)
Two. x has two elements, of which one is an array. If you want 3 as answer, a better name would be natoms. :-)
/ Mirar
Previous text:
2003-01-21 22:46: Subject: Death to strlen! Death to the demoness Allegra Geller!
But is nelems(x) for x=({ 1, ({ 2, 3 }) }) two or three?
/ Martin Nilsson (Åskblod)
Yes, but it is not so bad that it needs to be changed IMHO.
/ Martin Nilsson (Åskblod)
Previous text:
2003-01-21 09:41: Subject: Death to strlen! Death to the demoness Allegra Geller!
sizeof is also bad, the function should be called "size", "len" or "length".
/ Fredrik (Naranek) Hubinette (Real Build Master)
You have probably not been writing enough C to see the problem clearly. :-)
size() and/or len() would be better.
/ Per Hedbor ()
Previous text:
2003-01-21 16:20: Subject: Death to strlen! Death to the demoness Allegra Geller!
Yes, but it is not so bad that it needs to be changed IMHO.
/ Martin Nilsson (Åskblod)
I'm well aware of the problem. The problem "Pike is confusing for beginners" and "Pike is confusing for C programmers" are two different ones. I think it is enough to make Pike look like a consistent and thought through language on its own. Changes to make it more easy to go from X#++ to Pike has to have much more persuading arguments.
/ Martin Nilsson (Åskblod)
Previous text:
2003-01-21 16:42: Subject: Death to strlen! Death to the demoness Allegra Geller!
You have probably not been writing enough C to see the problem clearly. :-)
size() and/or len() would be better.
/ Per Hedbor ()
I would only vote for a new name for sizeof if there already are enough incompatible changes to make it necessary to go over old code more or less line by line.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-01-21 16:42: Subject: Death to strlen! Death to the demoness Allegra Geller!
You have probably not been writing enough C to see the problem clearly. :-)
size() and/or len() would be better.
/ Per Hedbor ()
len() is not good since it's illogical for, say, a mapping. size() of nelems() are better suggestions.
/ David Hedbor
Previous text:
2003-01-21 16:42: Subject: Death to strlen! Death to the demoness Allegra Geller!
You have probably not been writing enough C to see the problem clearly. :-)
size() and/or len() would be better.
/ Per Hedbor ()
In my oppinion, sizeof() is a far worse name than strlen(). Oppinions however, differ.
/ Fredrik (Naranek) Hubinette (Real Build Master)
Previous text:
2003-01-21 16:20: Subject: Death to strlen! Death to the demoness Allegra Geller!
Yes, but it is not so bad that it needs to be changed IMHO.
/ Martin Nilsson (Åskblod)
Not for a general size function :) But I think it has to do with the fact (it is a fact right?) that you are more used to C code. For someone that has never seen another programming langauge size or sizeof is probably better names than strlen.
/ Martin Nilsson (Åskblod)
Previous text:
2003-01-29 02:25: Subject: Death to strlen! Death to the demoness Allegra Geller!
In my oppinion, sizeof() is a far worse name than strlen(). Oppinions however, differ.
/ Fredrik (Naranek) Hubinette (Real Build Master)
Why not just change both to "size", and deprecate sizeof and strlen?
But I guess it'd be a minor hell to programmers who use "int size=sizeof..." :)
/ Mirar
Previous text:
2003-01-29 02:30: Subject: Death to strlen! Death to the demoness Allegra Geller!
Not for a general size function :) But I think it has to do with the fact (it is a fact right?) that you are more used to C code. For someone that has never seen another programming langauge size or sizeof is probably better names than strlen.
/ Martin Nilsson (Åskblod)
And we are back at 9621928. Woho, a completed circle!
/ Martin Nilsson (Åskblod)
Previous text:
2003-01-29 09:06: Subject: Death to strlen! Death to the demoness Allegra Geller!
Why not just change both to "size", and deprecate sizeof and strlen?
But I guess it'd be a minor hell to programmers who use "int size=sizeof..." :)
/ Mirar
pike-devel@lists.lysator.liu.se