Reading other people's code - I need to do this more often
Timothy D. Swieter
Posts: 1,613
Over the last week or so I have learned several tricks and techniques in Propeller programming from reading the latest book and from browsing more at other peoples code in the OBEX. I guess I get stuck in my own rut and don't add to the 'programming tools' much or improve my techniques. I have seen how other people structure their code and I picked up a trick or two every time I dive into code from someone else. I have been using the Propeller since it came out however I am a good example of why working in a group and reading other peoples work help to make me a better designer/programmer. Do others feel this way too?
While on this subject I have a couple things I have seen in fsrw SD card code that I haven't puzzled through yet, perhaps you can help:
-I have notice that there is a "\" before routine calls, why is this? For instance, in the 'test' file for fsrw, near the top, there is "x := \start", what does the "\" do?
-In the same 'test' file I noticed there is a "sdfat" in the object section. I assume this means they are declaring two objects, but how is this used? Only near the end do I see "sdfat" and everywhere else "sdfat[noparse][[/noparse]0]". Is "sdfat" is assumed to be "sdfat[noparse][[/noparse]0]"?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
While on this subject I have a couple things I have seen in fsrw SD card code that I haven't puzzled through yet, perhaps you can help:
-I have notice that there is a "\" before routine calls, why is this? For instance, in the 'test' file for fsrw, near the top, there is "x := \start", what does the "\" do?
-In the same 'test' file I noticed there is a "sdfat" in the object section. I assume this means they are declaring two objects, but how is this used? Only near the end do I see "sdfat" and everywhere else "sdfat[noparse][[/noparse]0]". Is "sdfat" is assumed to be "sdfat[noparse][[/noparse]0]"?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
Comments
It then returns the defined value: page 162 of the Prop Manual refers.
Disclaimer: I know very little about programming the Prop!
Regards,
T o n y
Post Edited (TonyWaite) : 2/13/2010 10:55:19 AM GMT
pretty much the same way try\catch blocks work in other high level languages such as C# and Java.
so you have something like this:
the -1 effectly goes straight to method A (b and c will not process the -1 because they did not have the \ when they called the method).
Very useful for returning error codes (which is how it is used in fsrw I believe).
As for the second question, looks like sdfat[noparse][[/noparse]0] should be the same as sdfat. The test in fsrw24 (the version I have on hand) only·mentions 'sdfat' and 'sdfat[noparse][[/noparse]1]' (indicating that 'sdfat' is assumed to be 'sdfat[noparse][[/noparse]0]').
Oh and as for the starting question... I only really look at other people's code when I am trying to alter it somehow. You're right though, I really should look at code more especially with all the nifty things I've seen people mentioning on this forum. When I get into pasm I'll probably have more motivation to look more closely at what some of the obex objects are doing 'under the hood'.
the metadata buffer, but each gets its own file buffer and can be separately open for read or write to
its own file.
localroger - are you sure that sdfat[noparse][[/noparse]0] would and take more code than sdfat? Is the 'compiler' the one doing the interpreting on [noparse][[/noparse]0] or lack of it and the code byte code in the Prop is the same no matter which?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
Compile it and look at the list file.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
1. You must fully understand the code before using it.
2. If you use a copy of the code in your program, the code must be public domain and has no licensing restrictions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Will work for Propeller parts!
there would be game programs or application programs on one or two pages or half a page.
I learned a lot about programming from entering those off the page, and from listing or disassembling ones other
people wrote. We had 16KB until our yearning for 64KB (maximum for 8-bit) was satisfied.
Hydra kit, and I think also Propeller Tool, include many sample programs.
Closed source holds many mysteries, most of all, why the precompiled software takes up a million times
more bytes than if I had wrote it and what black magic is being done so slowly with all that extra memory.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I should be typing in Spin now.
Coming soon. My open Propeller Project Pages and favorite links index.
more bytes than if I had wrote it..."
I like that. And I think I have the answer. It's a marketing trick.
You see, buying software is always a disappointment. You lay down your hard earned cash and what do you get? A floppy disk, a CD, a DVD. A few cents of plastic. Worse still you don't even get that just a download from the internet and a key to activate it. Nothing!
It gets worse. Even if the program you have scrimped and save for does something useful for you for a while it is soon starts getting old. New versions come, people start to moan at you that when you say you can't read their documents, spreadsheets, whatever any more. Time to upgrade and pay out again.
And again comes that disappointment, you get nothing!
So for a software vendor to make you feel a bit better about the abysmal situation they have got you into they have to make the installations exponentially bigger and bigger with every release. Just to try and make you feel you are getting something for your money. It's bigger and flashier it must be better and more desirable.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Post Edited (heater) : 2/14/2010 8:30:14 AM GMT
3. Perform unit and regression tests as required.
To fully understand the code, read it then re-write it the way you think it should be done, then you don't have to worry about 2. Of course that approach is impractical for a larger code library. If a library doesn't have clean interfaces, it will most likely cause pain whether you understand the underlying code or not [noparse]:)[/noparse] Just my $0.02 ....