[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Shorthand for appending to a table (was Re: 5.2 feature list?)
- From: Philippe Lhoste <PhiLho@...>
- Date: Tue, 12 Sep 2006 17:30:57 +0200
Kucera, Rich a écrit :
I think the search is for a meaningful syntax that does something, does some
work, and the madness to be avoided is a syntax that does nothing, for
example:
void convertToDisplayValues( HashMap recordForView ) {
Iterator iter = recordForView.keySet().iterator();
while ( iter.hasNext() ) {
String fieldName = (String)iter.next();
if ( ((String)recordForView.get(fieldName)).equals("on") ) {
recordForView.put(fieldName, "*** ADD ***");
}
...
Java 1.5 has an "improved" 'for' syntax, which is close of the foreach
below.
Something like:
for (String rfv : recordForView)
We still have the abuse of castings, and the clumsy equals method.
They made the String class special (the only one with overloaded
operator and special syntax for values (double quotes)), they could have
overloaded == too.
The same thing in PHP actually starts to reveal some meaning, do some work:
function convertToDisplayValues( $recordForView ) {
foreach ( $recordForView as $fieldName => $fieldVal ) {
if ( $fieldVal == "on" ) {
$recordForView[$fieldName] = "*** ADD ***";
}
...
Probably the same thing in Python would be even more concise. I don't know
what this blurb would look like in Lua because I haven't written any Lua yet
:-) ...Can someone please?
Perhaps something like:
function convertToDisplayValues(recordForView)
for fieldName, fieldVal in pairs(recordForView) do
if fieldVal == 'on' then
recordForView[fieldName] = "*** ADD ***"
end
end
end
Untested as I am not too sure what this is supposed to do...
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --