"case" or better? (2.6 suggestion mode)
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Apr 03, 2005
- 515 views
I erm, don't erm, oh... Sigh )) I recently found I had written this, to handle five distinct functions; escape key (==Cancel), return key (==OK), pressing the OK and Cancel buttons, and closing the window:
if msg = WM_CHAR then if wParam = VK_ESCAPE then id = PFcncl msg = WM_COMMAND elsif wParam = VK_RETURN then msg = WM_COMMAND end if end if if msg = WM_COMMAND then if id = PFcncl then -- cancel FaceIdx=InitFaceIdx PointIdx=InitPointIdx applyFont() -- else assume PFOK end if msg = WM_CLOSE end if if msg = WM_CLOSE then isFaceName = faces[FaceIdx] if FaceIdx>=5 then isPointSize = sizes[FaceIdx][PointIdx] end if setVisible(PFwin,False) return 1 end if return 0
Of course, it works perfectly ) What I've done is repeatedly reset a controlling var to "fall through" I perhaps naturally /thought/ I could rewrite it better using case, but I couldn't. It was so appalling I refuse to post it here. Three points sprang to mind: 1) the main argument for case is the "fall through" 2) the main argument against case is the "fall through" / forgetting break. 3) I vote No Thanks. It just reminded me why case/select sucks. Regards, Pete