lua-users home
lua-l archive

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


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
--  --  --  --  --  --  --  --  --  --  --  --  --  --