"case" or better? (2.6 suggestion mode)

new topic     » topic index » view thread      » older message » newer message

I erm, don't erm, oh...   Sigh blink))

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

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu