Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] rebol weak points (i think) Re:(3)

From: brian:hawley:bigfoot at: 9-Sep-2000 10:05

[rishi--picostar--com] wrote:
>no. The Math/Pie you have created is an instance variable not a static >variable. It is associated with an instance of the class, not the class >itself. A static variable means that there is a single copy of this variable >associated with class itself. You do not need to instantiate a class to use >static variable.
You have it backwards. REBOL doesn't have classes. OOP in REBOL is prototype/delegation based, like Self, NewtonScript or JavaScript - not class-based like C++, Smalltalk or Java. Objects in REBOL are all unique. Their behavior is defined within themselves using static variables, rather than through their class. They are created from prototypes, not classes. Constructors are just functions. You don't inherit the features of a class, you call them directly - this is known as delegation. All fields are static - any instance objects you create call the "class" objects directly. This style of object-oriented programming, used properly, can be more efficient than class-based programming. If you really need classes they're a simple design pattern away.
>For example: > >make-circle: make func [ > radius > /local blah-blah-blah > /static num_circles ;let's say this is how you create static var. >] [ > num_circles: num_circles + 1 ;this may not be correct but you get the >idea... > return make object! [ > ;object code goes here > ] >]
There are techniques for making persistent values in functions - most of them are arcane (but fun). Functions don't have static variables as such but you can embed structured data in the code of the function. Most of the time it's better to use objects. Try this: circle-class: make object! [ num-circles: 0 new: func [value [number!]] [ num-circles: num-circles + 1 make object! compose [ class: (self) radius: value num-circles: func [] [class/num-circles] ] ] ] (skipped a little...)
>The main disadvantage of having static variables is that perhaps it is an >unnecessary complication. But I don't think so. Maybe because I come from >java/javascript background. I'm still wondering though if there is a way to >have static variables that I don't know.
It's interesting that you mention Java and JavaScript in the same sentence here. Java is class-based like C++. JavaScript is more like REBOL - all variables are static, constructor functions, class factory objects instead of classes. The object model of JavaScript has been traditionally confusing for those who think OOP is only class-based...
>Regardless, the main problem that I wonder about is if rebol is suited for >modular programming where people reuse other people's functions/code. Since >everything is either global or local, it seems as though it would be >unnatural to use rebol in this way. Java has packages and stuff...
Coming from a background of Oberon, Delphi and such (among many others) I'd have to agree. Fortunately RT has listened :) Look at this: http://www.rebol.com/reps/rep002.html It's a little outdated - many changes have purportedly been made already but they haven't been codified yet. I gather security support will be much improved. Still, it's a taste of things to come. I'm looking forward to it :)
>Perhaps I am not thinking straight and have too much java in my >blood (which I have been doing to much of lately and finally got >sick of all the abstractions that got in the way of doing simple >stuff!!)
Tell me about it :( I'm having the opposite problem. I just got put on a project that is being done with ColdFusion, a web template language like ASP. I can't go 5 minutes without running into some limitation that would be trivial to overcome with REBOL. Maybe I can do the next round with REBOL/Serve when it comes out... Brian