Now, granted, there is much that is done on the API-side to make life more custom fit for each language, but given equal attention to doing this particular task, it's interesting to take this snapshot comparison of exactly equal functionality:
( php ) ✂
foreach( $this->works->each( $wholeOrder, $whichway ) as $work )
$this->page->setMultipleFieldsForTemplate( 'work', array(
'title' => $work['title'],
'author' => $work['author'],
'years' => $work['startyear'] .
( $work['startyear']==$work['endyear'] ? '' : '-'.$work['endyear'] ),
'titleStyle' =>
( $work['id']==$currentID ? 'bookCurrent' :
( ( $work['important']=='Y' and $work['done']==1 ) ? 'bookImp' :
( $work['done']==1 ? 'bookNotImpDone' : 'bookNotImp' ))),
'bookStyle' =>
( $work['id']==$currentID ? 'bookCurrent' :
( $work['done']==1 ? 'bookDone' : 'bookUndone' )),
));
1 foreach ( $this->works-> each ( $wholeOrder , $whichway ) as $work ) 2 $this->page-> setMultipleFieldsForTemplate ( 'work' , array ( 3 'title' => $work ['title' ], 4 'author' => $work ['author' ], 5 'years' => $work ['startyear' ] . 6 ( $work ['startyear' ]==$work ['endyear' ] ? '' : '-' .$work ['endyear' ] ), 7 'titleStyle' => 8 ( $work ['id' ]==$currentID ? 'bookCurrent' : 9 ( ( $work ['important' ]=='Y' and $work ['done' ]==1 ) ? 'bookImp' : 10 ( $work ['done' ]==1 ? 'bookNotImpDone' : 'bookNotImp' ))), 11 'bookStyle' => 12 ( $work ['id' ]==$currentID ? 'bookCurrent' : 13 ( $work ['done' ]==1 ? 'bookDone' : 'bookUndone' )), 14 ));The F-Script code has no "?:" style conditional, but has (testCondition) ifTrue:[…] ifFalse:[…] conditional. Wordier, but does lend itself to some improved readability. Nesting them requires more concentration, but that's even more true with the "?:"-styled code above.
( fscript ) ✂
workBlock := [ :work | {
'title', work valueForKey:'title',
'author', work valueForKey:'author',
'years',
(work valueForKey:'startyear')++
((work valueForKey:'startyear') = (work valueForKey:'endyear')
ifTrue:[''] ifFalse:[ '-'++((work valueForKey:'endyear') printString) ]),
'titleStyle',
((work valueForKey:'id') = currentId
ifTrue: [ 'bookCurrent' ]
ifFalse:[ ((work valueForKey:'important')='Y') & ((work valueForKey:'done')=1)
ifTrue: [ 'bookImp' ]
ifFalse:[ (work valueForKey:'done') = 1
ifTrue: [ 'bookNotImpDone' ]
ifFalse:[ 'bookNotImp' ] ] ] ),
'bookStyle',
((work valueForKey:'id') = currentId
ifTrue: [ 'bookCurrent' ]
ifFalse:[ (work valueForKey:'done') = 1
ifTrue: [ 'bookDone' ]
ifFalse:[ 'bookUndone' ] ])
} ].
page setMultipleFields:allWorks usingBlock:workBlock forField:'work'.
1 workBlock := [ :work | { 2 'title' , work valueForKey :'title' , 3 'author' , work valueForKey :'author' , 4 'years' , 5 ( work valueForKey :'startyear' ) ++ 6 ( ( work valueForKey :'startyear' ) = ( work valueForKey :'endyear' ) 7 ifTrue :['' ] ifFalse :[ '-' ++( ( work valueForKey :'endyear' ) printString) ] ) , 8 'titleStyle' , 9 ( ( work valueForKey :'id' ) = currentId 10 ifTrue : [ 'bookCurrent' ] 11 ifFalse :[ ( ( work valueForKey :'important' ) ='Y' ) & ( ( work valueForKey :'done' ) =1) 12 ifTrue : [ 'bookImp' ] 13 ifFalse :[ ( work valueForKey :'done' ) = 1 14 ifTrue : [ 'bookNotImpDone' ] 15 ifFalse :[ 'bookNotImp' ] ] ] ) , 16 'bookStyle' , 17 ( ( work valueForKey :'id' ) = currentId 18 ifTrue : [ 'bookCurrent' ] 19 ifFalse :[ ( work valueForKey :'done' ) = 1 20 ifTrue : [ 'bookDone' ] 21 ifFalse :[ 'bookUndone' ] ] ) 22 } ] . 23 page setMultipleFields :allWorks usingBlock :workBlock forField :'work' . One thing that could make me happier with the fscript code is if I could write at:'…' instead of valueForKey:'…'. I think the result would match one's intuition for a dictionary lookup. I could always add it as a category to NSDictionary, I guess.