Shop OBEX P1 Docs P2 Docs Learn Events
Reading other people's code - I need to do this more often — Parallax Forums

Reading other people's code - I need to do this more often

Timothy D. SwieterTimothy D. Swieter Posts: 1,613
edited 2010-02-14 17:43 in Propeller 1
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

Comments

  • TonyWaiteTonyWaite Posts: 219
    edited 2010-02-13 10:50
    Is this the 'abort' trap, inserted in case the routine aborts?

    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
  • Kal_ZakkathKal_Zakkath Posts: 72
    edited 2010-02-13 11:15
    Yes the slash ("\") is for catching aborts. That is, somewhere in the code calls 'abort(num)', the abort then propagates up until it is caught.
    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:
    Method A calls \B.method
    b.method calls c.method
    c.method calls d.method
    d.method calls abort(-1)
    

    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'.
  • localrogerlocalroger Posts: 3,452
    edited 2010-02-13 13:01
    Yes, Spin does not draw a distinction between sdfat and sdfat[noparse][[/noparse]0], making a hardcoded [noparse][[/noparse]0] nothing but a pure waste of hub ram.
  • rokickirokicki Posts: 1,000
    edited 2010-02-13 18:13
    Right. The "two" sdfat objects means two files can be used simultaneously. They will share code and
    the metadata buffer, but each gets its own file buffer and can be separately open for read or write to
    its own file.
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2010-02-14 04:16
    Thanks guys for the feedback on those couple of items I hadn't figured out yet.

    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
  • BradCBradC Posts: 2,601
    edited 2010-02-14 05:22
    Timothy D. Swieter said...
    Thanks guys for the feedback on those couple of items I hadn't figured out yet.

    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?

    Compile it and look at the list file.

    OBJ
      Fred : "FullDuplexSerial"
    
    PUB A
      Fred.RxCheck
    
    PUB B
      Fred[noparse][[/noparse]0].RxCheck
    
    



    PUB A
    
    Local Parameter DBASE:0000 - Result
    |===========================================================================|
    5                        Fred.RxCheck
    Addr : 0020:             01  : Drop Anchor   
    Addr : 0021:       06 03 06  : Call Obj.Sub 3 6
    Addr : 0024:             32  : Return        
    |===========================================================================|
    Spin Block B with 0 Parameters and 0 Extra Stack Longs. Method 2
    PUB B
    
    Local Parameter DBASE:0000 - Result
    |===========================================================================|
    8                        Fred[noparse][[/noparse]0].RxCheck
    Addr : 0025:             01  : Drop Anchor   
    Addr : 0026:             35  : Constant 1 $00000000
    Addr : 0027:       07 03 06  : Call Obj.Sub[noparse][[/noparse] ]3 6
    Addr : 002A:             32  : Return        
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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.
  • blittledblittled Posts: 681
    edited 2010-02-14 06:38
    As for your question about looking at other people's code, I as a professional programmer, utilize other people's programs as a tool to help solve many of the problems I come across. There are 2 rules I use when doing this.

    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!
  • VIRANDVIRAND Posts: 656
    edited 2010-02-14 08:01
    Way way back in the days of "Creative Computing" and BYTE and Kilobaud Microcomputing Mazazines,
    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.
  • heaterheater Posts: 3,370
    edited 2010-02-14 08:24
    VIRAND: "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..."

    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
  • jazzedjazzed Posts: 11,803
    edited 2010-02-14 17:43
    blittled said...
    As for your question about looking at other people's code, I as a professional programmer, utilize other people's programs as a tool to help solve many of the problems I come across. There are 2 rules I use when doing this.

    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.
      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 ....
Sign In or Register to comment.