Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Crap code
Message
From
12/05/2021 17:17:46
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
26/04/2021 16:15:30
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01679827
Message ID:
01680342
Views:
55
>>>I inherited a bunch of crap code. I don't defend crap, even if I write it.
>
>No judgment here, just celebrating all the ways to achieve the same goal in VFP, some of which look ugly but are speedy while others appear elegant but carry overhead. Substr() would be an obvious example of a concise but potentially inefficient way to get things done, depending on string size. I join these exchanges in case somebody else has gems to share on performance or entirely new ways to achieve goals.

I don't celebrate all the ways. I celebrate the best ways. An experienced mechanic won't stick 2 wires into an engine's cylinder and call it a spark plug, though that certainly is one of all ways. Those programmers who think they already know the best ways can either put up or shut up. I am showing how to think about scans and nested IFs so they can write better code. That's the whole point of these forums except for the fake experts and security guards and entrepreneurs who think they can program.
		GO top
			SCAN
				IF wScanForEndOfDay = 1
					replace ScanGrL.OutForEOD WITH 0
				endif
				wMessBody = wMessBody + CHR(13) + ALLTRIM(STR(ScanGrL.OrdNmb))
			ENDSCAN
			wnAnswer = MESSAGEBOX(wMessBody, 4 + 32 + 256, goApp.cCaption)
The GO TOP is stupid since the scan will start at the top. This is a case of knowing how FoxPro works. The wScanForEndOfDay is a memory variable. It will not change as the scan runs. So why execute it once per row - something SQL Server people call RBAR - row by agonizing row? Seems they don't like slow crap. While the code is going through all the rows it does a replace. One fake expert here claimed that mdot is not important, but without knowing wScanForEndOfDay is a memvar, it is included in the loop which is wasteful. Knowing it is a memvar - and where has this w prefix come from? It's not hungarian notation, so how can we tell? mdot makes it obvious to programmers and the compiler. Naming conventions only help those who share them. I don't behave like a Nazi and force people to use my preferred convention. I don't even force anyone to use mdot. I use it because it is bullet proof. I'm not interested in silly code cosmetics. As long as I can read and maintain it with clarity and the compiler can execute it with speed and safety, all the better. Conventions are of little benefit when the compiler does not use those conventions.

The optimization I was demonstrating was for the number of steps through a set of records, not whether alltrim(str()) is better than transform. I will show such code here even if some crap coders get upset.
		IF m.wScanForEndOfDay = 1
				REPLACE OutForEOD WITH 0 for OutForEOD<>0 in ScanGrL
			endif
			SCAN
				wMessBody = m.wMessBody + CHR(13) + ALLTRIM(STR(OrdNmb))
			ENDSCAN
			wnAnswer = MESSAGEBOX(m.wMessBody, 4 + 32 + 256, m.goApp.cCaption)
The last point is why is an application object holding a caption? That is not even close to proper scope.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform