Announcement

Collapse
No announcement yet.

Shortened Procedure Nomenclature

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shortened Procedure Nomenclature

    It's annoying (not that much, but enough to raise the question) to have to write this:

    Code:
    Function WinMain (ByVal hInst As Dword, ByVal hPrevInstance As Dword, ByVal lpCmdLine As Asciiz PTR, ByVal iCmdShow As Long) As Long
    Is there no shortened nomenclature that the compiler would accept? As I've noted before I like short code and I don't like line continuations. I'd rather have optional shortcut nomenclature - such as this:

    Code:
    Fn WinMain(hInst DW,hPrev DW,Line A_P,Show L) Long_v
    where, the _b says all arguments are ByVal unless otherwise stated.

    Is there any prior history on something like this? The compiler would have to be compatible with Windows API syntax, but could be a buffer for the user. I'd rather think than type, and for sure, I'd rather view than scroll.

    And yes, I understand there's the issue of being able to read the code later on, or for others to maintain the code, but still - that's why it would be optional. Let the programmer decide. For that matter, there could be an IDE "Expand" function, which expands the code to the more conventional syntax before archiving it.
    Last edited by Gary Beene; 20 Sep 2009, 11:46 AM.

  • #2
    Well, you could try using MACROs.

    But seriously, is it really THAT much effort to type important keywords such as FUNCTION, SUB and BYVAL?

    Have The Youth of America lost ALL sense of work ethic?
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Use macros, e.g.

      Code:
      MACRO WMAIN = Function WinMain (ByVal hInst As Dword, ByVal hPrevInstance As Dword, ByVal lpCmdLine As Asciiz PTR, ByVal iCmdShow As Long) As Long
      MACRO EF = END FUNCTION
      Usage:

      Code:
      WMAIN
      
      EF
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


      • #4
        I don't see the need for this either. With todays large monitors and high resolution displays, you can get a lot of text on screen at once. If you want faster typing, get an editor that supports auto completion so that you don't need to type entire words. If you wanted to do this, however, like Michael said, MACROs are your friend:

        Code:
        MACRO Fn  = FUNCTION
        MACRO DW  = AS DWORD
        MACRO A_P = AS ASCIIZ POINTER
        MACRO L   = AS LONG
        MACRO BV  = BYVAL
        
        Fn WINMAIN(BV hInst DW, BV hPrev DW, BV pLine A_P, BV iShow L) L
        
            MSGBOX "It works!"
        
        END Fn
        Jeff Blakeney

        Comment


        • #5
          Code:
          MSGBOX "It works!"
          Until you begin to get conflicts with variable names, etc. Choose the names of the macros carefully, adding a prefix or a suffix.
          Forum: http://www.jose.it-berater.org/smfforum/index.php

          Comment


          • #6
            Originally posted by José Roca View Post
            Until you begin to get conflicts with variable names, etc. Choose the names of the macros carefully, adding a prefix or a suffix.
            Very true. That's why I don't think it is even worth the bother. Once you start adding prefixes and such, you end up typing almost as much anyway.
            Jeff Blakeney

            Comment


            • #7
              Code:
              MACRO L   = AS LONG
              MACRO BV  = BYVAL
              
              Fn WINMAIN(BV hInst DW, BV hPrev DW, BV pLine A_P, BV iShow L) L
              Oops. "BV pLine" is going to come out "BYVAL pAS LONGine"

              I think that's an "AS or type specifier expected" error.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                This thread is so 90's. There was a segment on 60 Minutes tonight where amputees can just think what they want and move an articulated arm/hand.

                Zale and Company should be working on a method of gluing a couple of padded sensors on Mr. Beene's head so that what he thinks should work will be typed out in PB Edit. And maybe hooked wirelessly to Mr. Mathias' brain pads to keep Mr. Beene on the straight and narrow WPI path.

                =============================================
                "It is vain to do with more
                what can be done with less."
                William of Occam (c. 1285-1349), British monk
                =============================================
                It's a pretty day. I hope you enjoy it.

                Gösta

                JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                Comment


                • #9
                  Code:
                  Fn WinMain(hInst DW,hPrev DW,Line A_P,Show L) Long_v
                  I look forward to the day when code like this is posted in the forum and the author asks for help.

                  Forth is better for this.

                  Comment


                  • #10
                    Originally posted by Michael Mattias View Post
                    Oops. "BV pLine" is going to come out "BYVAL pAS LONGine"

                    I think that's an "AS or type specifier expected" error.
                    Apparently that doesn't happen because the code I posted compiles and runs without a problem. I think MACRO substitutions only happen on whole words so the L in pLine doesn't get replaced.
                    Jeff Blakeney

                    Comment


                    • #11
                      I think I can C a way.

                      Code:
                      long WinMain (dword hInst,hPrev,*lpCmdLine,long iCmdShow)
                      {
                      PRINT "DLROW"
                      PRINT "OLLEH"
                      }
                      You eliminate FUNCTION, AS, and END FUNCTION. A pointer is already a DWORD, so just a * to pass it.

                      I don't know a quasi-C syntax option really would be good for PB. It is briefer, but PB still lacks the verbosity that COBOL is (in)famous for.
                      Erich Schulman (KT4VOL/KTN4CA)
                      Go Big Orange

                      Comment


                      • #12
                        The C syntax is one of the reasons I don't use C. It is very hard to read. I also don't use the new PB compound operators for the same reason.
                        Jeff Blakeney

                        Comment


                        • #13
                          Is there no shortened nomenclature that the compiler would accept?
                          Shorter and accepted,

                          Function PBMAIN
                          ...
                          End Function

                          Comment


                          • #14
                            I think MACRO substitutions only happen on whole words so the L in pLine doesn't get replaced.
                            I had never used a macro other than 'whole word.'
                            I RTFM.
                            Doc does not contain this restriction.
                            I tested.
                            You are correct.
                            Bug report sent.


                            MCM
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              There's no bug involved. A macro statement works with whole words, just like every other PowerBASIC statement. If it did not, we would have cause to document that as unusual behavior.

                              If you have a variable named GoToExit, I hope you have no question that the compiler is not going to treat it as GOTO and EXIT statements. By the same token, having a macro named ToExit is not going to affect the name GoToExit. This is just basic BASIC syntax.

                              Comment


                              • #16
                                A macro statement works with whole words, just like every other PowerBASIC statement
                                Well, then, this concise and easily-understood statement belongs on the help file page for MACRO, doesn't it?

                                It ain't there.

                                ===> Documentation bug.

                                MCM
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  That said, it appears at least one person at PowerBASIC agrees with my assessment...

                                  Hi Michael,

                                  I have logged this with our documentation team, thank you.

                                  Sincerely,
                                  Jeff Daniels
                                  PowerBASIC Staff

                                  Michael Mattias wrote:
                                  > 9/23/09
                                  >
                                  > PB/WIN 9.0.1/IDE compiler.
                                  >
                                  > MACRO is only substituting only when "whole word" found. Doc does
                                  > not include said limitation.
                                  >
                                  > Documented behavior does not equal observed behavior. Bug.
                                  >
                                  If you hurry, you can probably get your excellent wording to the "documentation team", making it easy to incorporate this important fact into the very next help file update.
                                  Last edited by Michael Mattias; 23 Sep 2009, 10:31 AM.
                                  Michael Mattias
                                  Tal Systems (retired)
                                  Port Washington WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    I'm in complete agreement with Gosta! Way to go Gosta!

                                    Anybody ever heard of copy / paste inheritance?

                                    Anyway, if you don't like the basic WinMain() function signature - just get rid of it and use the simpler PBMain() instead. Here is my basic Form1 Sdk template app with WinMain() removed and PBMain() put in its place...

                                    Code:
                                    #Compile Exe
                                    #Include "Win32api.inc"
                                    
                                    Type WndEventArgs
                                      wParam As Long
                                      lParam As Long
                                      hWnd   As Dword
                                      hInst  As Dword
                                    End Type
                                    
                                    Declare Function FnPtr(wea As WndEventArgs) As Long
                                    
                                    Type MessageHandler
                                      wMessage As Long
                                      dwFnPtr As Dword
                                    End Type
                                    Global MsgHdlr() As MessageHandler
                                    
                                    
                                    Function fnWndProc_OnCreate(wea As WndEventArgs) As Long
                                      Local pCreateStruct As CREATESTRUCT Ptr
                                    
                                      pCreateStruct=wea.lParam
                                      [email protected]
                                    
                                      fnWndProc_OnCreate=0
                                    End Function
                                    
                                    
                                    Function fnWndProc_OnNotify(wea As WndEventArgs) As Long
                                      fnWndProc_OnNotify=0
                                    End Function
                                    
                                    
                                    Function fnWndProc_OnClose(wea As WndEventArgs) As Long
                                      Call DestroyWindow(wea.hWnd)
                                      Call PostQuitMessage(0)
                                      fnWndProc_OnClose=0
                                    End Function
                                    
                                    
                                    Function fnWndProc(ByVal hWnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As Long) As Long
                                      Static wea As WndEventArgs
                                      Register iReturn As Long
                                      Register i As Long
                                    
                                      For i=0 To 2
                                        If wMsg=MsgHdlr(i).wMessage Then
                                           wea.hWnd=hWnd: wea.wParam=wParam: wea.lParam=lParam
                                           Call Dword MsgHdlr(i).dwFnPtr Using FnPtr(wea) To iReturn
                                           fnWndProc=iReturn
                                           Exit Function
                                        End If
                                      Next i
                                    
                                      fnWndProc=DefWindowProc(hWnd,wMsg,wParam,lParam)
                                    End Function
                                    
                                    
                                    Sub AttachMessageHandlers()
                                      ReDim MsgHdlr(2) As MessageHandler  'Associate Windows Message With Message Handlers
                                      MsgHdlr(0).wMessage=%WM_CREATE   :   MsgHdlr(0).dwFnPtr=CodePtr(fnWndProc_OnCreate)
                                      MsgHdlr(1).wMessage=%WM_NOTIFY   :   MsgHdlr(1).dwFnPtr=CodePtr(fnWndProc_OnNotify)
                                      MsgHdlr(2).wMessage=%WM_CLOSE    :   MsgHdlr(2).dwFnPtr=CodePtr(fnWndProc_OnClose)
                                    End Sub
                                    
                                    
                                    Function PBMain() As Long
                                      Local szAppName As Asciiz*16
                                      Local hWnd,hIns As Dword
                                      Local wc As WndClassEx
                                      Local Msg As tagMsg
                                    
                                      hIns=GetModuleHandle("")
                                      szAppName="Form1"                               : Call AttachMessageHandlers()
                                      wc.lpszClassName=VarPtr(szAppName)              : wc.lpfnWndProc=CodePtr(fnWndProc)
                                      wc.cbClsExtra=0                                 : wc.cbWndExtra=0
                                      wc.style=%CS_HREDRAW Or %CS_VREDRAW             : wc.hInstance=hIns
                                      wc.cbSize=SizeOf(wc)                            : wc.hIcon=LoadIcon(%NULL, ByVal %IDI_APPLICATION)
                                      wc.hCursor=LoadCursor(%NULL, ByVal %IDC_ARROW)  : wc.hbrBackground=%COLOR_BTNFACE+1
                                      wc.lpszMenuName=%NULL
                                      Call RegisterClassEx(wc)
                                      hWnd=CreateWindow(szAppName,"Form1",%WS_OVERLAPPEDWINDOW,200,100,325,300,0,0,hIns,ByVal 0)
                                      Call ShowWindow(hWnd,%SW_SHOWNORMAL)
                                      While GetMessage(Msg,%NULL,0,0)
                                        TranslateMessage Msg
                                        DispatchMessage Msg
                                      Wend
                                    
                                      Function=msg.wParam
                                    End Function
                                    Last edited by Fred Harris; 23 Sep 2009, 11:39 AM. Reason: add line
                                    Fred
                                    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                                    Comment


                                    • #19
                                      What I really like about this forum is that you can post a question and gets several answers - quick responses and useful answers.

                                      What makes me grin about these forums is that you can post a request for something and get two dozen postings saying:

                                      1 You don't really want that!
                                      2 Why would anyone want that?
                                      3 I don't want that
                                      4 You shouldn't do it that way
                                      5 What a bad idea
                                      6 It's too hard
                                      7 It won't work
                                      8 It's not the way PowerBASIC works
                                      9 It's not how I would do it
                                      10 I already asked for it
                                      11 PowerBASIC Inc would never do that
                                      12 PowerBASIC Inc should not do that
                                      13 Here is something better
                                      14 It can't be done
                                      15 You've asked for too much
                                      16 You've asked for too little
                                      17 I agree with what he said
                                      18 What he said isn't right at all
                                      19 What he said isn't quite right
                                      20 I don't want to talk about that, instead, let's talk about this
                                      21 That would be too easy
                                      22 Real men like to type a lot
                                      23 Real men type in API, SDK, assembly language, machine language, bits
                                      24 You're not a real man
                                      25 Where are the women in this forum? (sorry, off-topic on that one)
                                      26 You could do that if you programmed in <language of your choice>
                                      27 Do you realize what you're asking?

                                      The one thing you absolutely do not get in these forums, is silence!

                                      And genetics is out the door here. I can plant an idea and by the time I come back to see what grew I sometimes can't figure out what I planted!

                                      But, I love to grin, so I'll keep posting my zany ideas. But in the future, all you have to do is say "#5", and I'll look at my list to see what that means! That would be consistent with my expressed love of succinct code!

                                      (I stole that #5 idea from a joke about a prison that had only 1 joke book in the library, so when someone wanted to tell a joke, they just yelled out the # of the joke).

                                      I have to go ... I'm working on the wording for another ... good idea?

                                      Ok, I had my fun. Serious now. Thanks for all the feedback guys. I really do appreciate the exposed opinions and thinking that goes on behind the responses. It would be really boring if all I got were simple answers.

                                      Comment


                                      • #20
                                        #21
                                        Fred
                                        "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                                        Comment

                                        Working...
                                        X