Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Experiment - Simple windowed application

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> ViviFire language
View previous topic :: View next topic  
Author Message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 728

PostPosted: Feb 24th, 2012, 10:49am    Post subject: Experiment - Simple windowed application Reply with quote

This is an attempt to translate a Rosetta Code task into what I think VF might look like.
Code:
require stdwindows #windows

object #demo is window
    title = "Rosetta Task: Simple windowed application"
    button #btn, "Click Me", btnClick, 20, 50, 100, 25
    statictext #num, "There have been no clicks yet.", 20, 100, 240, 30
    sub btnClick #sender
        static nClicks
        nClicks += 1
        #num "The button has been clicked ";nClicks;" times."
    end sub
end object

#demo show()
do wait while #windows count?
end

Require - a list of modules the program requires. The handle is optional and allows access to module-level methods.
Object - defines an object commonly called a Singleton. This is convenient when we don't need a full-blown class.
Is - indicates the parent from which a child class/object inherits some functionality.
Title - a method exposed by the Window class. The line could also be written title("Rosetta blah blah"). The equals sign can be used when a method has just one argument.
Button - a class exposed by StdWindows. The line it starts declares an object that is private to #demo. btnClick is the name of a subroutine. (I think no labeled event handlers for VF.) Unlike LB, UL and the like are optional. The button constructor literally takes a Rect object from which UL is derived. In VF, anywhere an object argument is expected, we can pass what that object's constructor expects instead. This may also allow for a flowing arrangement rather than pixel coordinates.
Sub - looks and works very much like LB. Subs and functions are private inside classes. If this were to use Method instead, that would be exposed.
Static - similar to LB's Global but the variable is local in scope to the sub. It lives as long as the object does.
+= - assigns the sum of the variable and the RHS expression to the same variable. Copied from C-like languages.
Show() - calls the method exposed by the Window class. Windows are hidden until explicitly shown.
Do - permits defining a very tight loop - one with just a single statement. The line waits for all windows to close. The question mark is an optional replacement for the empty parentheses.

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
STPendl
Full Member


Joined: 20 Aug 2007
Posts: 161
Location: Austria

PostPosted: Feb 25th, 2012, 9:49am    Post subject: Re: Experiment - Simple windowed application Reply with quote

I like the idea and the code is clean.
_________________
Stefan

Any code I post can be freely used, just give credit.
Back to top
View user's profile Send private message
nukesrus21
Junior Member


Joined: 19 Oct 2010
Posts: 13
Location: Southbury, CT

PostPosted: Apr 23rd, 2012, 10:20am    Post subject: Re: Experiment - Simple windowed application Reply with quote

Brent,

I've been looking this stuff over. Pretty neat stuff!!

Just a thought here............

I am not sure how I would feel about this:
Code:
static nClicks


Maybe something like:
Code:
protected nClicks

'or

local nClicks


When I see the word "static" I just think of something that is unchanging.


{:0)

Brandon

EDIT: ..... What is all this garbage that is showing up down here? It doesn't show up in the preview. Looks like something from Stefan's post. .....
Back to top
View user's profile Send private message
Alyce
Full Member


Joined: 04 Jul 2005
Posts: 91

PostPosted: Apr 23rd, 2012, 10:49am    Post subject: Re: Experiment - Simple windowed application Reply with quote

@Brandon, I don't have experience with too many languages, so I cannot speak with a lot of confidence, but...

In Visual Basic, a static variable (sounds like a contradiction in terms) is one that is local in scope, but retains its value even after a function returns. The next time the function is called, the value persists. It's not visible to the main program like a variable declared globally. To me, it seems like a way to include OOP features in a non-OOP language.

http://www.1sayfa.com/1024/diger/vb/ch07.htm#Heading12

_________________
- Alyce
Back to top
View user's profile Send private message Visit poster's website
RichardRussell
Full Member


Joined: 28 Jan 2012
Posts: 57
Location: Downham Market, UK

PostPosted: Apr 23rd, 2012, 1:19pm    Post subject: Re: Experiment - Simple windowed application Reply with quote

nukesrus21 wrote:
Maybe something like:
Code:
protected nClicks
'or
local nClicks

My personal preference is for:
Code:
private nClicks

I share your dislike of static. It originates from C, I think, in which it has multiple (and confusing IMHO) meanings. To me local doesn't imply that the value is preserved from one call to the next, which is the key feature.

Richard.
Back to top
View user's profile Send private message Visit poster's website
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 728

PostPosted: Apr 23rd, 2012, 4:45pm    Post subject: Re: Experiment - Simple windowed application Reply with quote

The "static" keyword may have originated with C, but my usage in the example derives from its use in QBasic. The following is valid QBasic.
Code:
SUB counter
    STATIC c
    c = c + 1
END SUB

If you want to know more about the concept, try http://en.wikipedia.org/wiki/Static_variable.

The original example could be rewritten (including updated naming) as
Code:
require StdGUI #gui

object #demo is window
    var nClicks ' private to the object
    title = "Rosetta Task: Simple windowed application"
    button #btn, "Click Me", btnClick, 20, 50, 100, 25
    statictext #num, "There have been no clicks yet.", 20, 100, 240, 30
    sub btnClick #sender
        nClicks += 1
        #num "The button has been clicked ";nClicks;" times."
    end sub
end object

#demo show()
do wait while #gui WindowCount?
end

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
JosephE
Junior Member


Joined: 01 Nov 2007
Posts: 21

PostPosted: May 15th, 2012, 2:41am    Post subject: Re: Experiment - Simple windowed application Reply with quote

If this is how it ends up, this could quite possibly be the most wonderful programming language ever created. I'm going to start reading about this.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> ViviFire language All times are GMT
Page 1 of 1
Jump to:  
Quick Reply
Username:
Message:
   Shortcut keys: Alt+Q to activate, Alt+P to preview, Alt+S to submit
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group