News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

to OOPS or not to OOPS

Started by Klod, September 22, 2007, 12:54:18 AM

Previous topic - Next topic

Klod

Lately, as I learn more, my programs have become more complex. I have been looking at various Oops models as they have been presented/demonstrated on this and various other asm boards. These models rely heavily on macros to make them work. My knowledge of preprocessor directives is not advanced enough to fully understand all aspects. I played around long enough to be able to use them, but feel uncomfortable doing so.
Browsing the various boards, I also learned, that there is great division among asm programmers about this topic.
I like the idea to keep some code and data together, like oops, but I also wonder if there are other ways available to achieve the same goal without the down sides. I am programming with masm.
Your input and suggestions are sought.
Regards KLOD 

Rockoon

OOP doesnt really keep code and data together....

Can you describe precisely what you desire?

What I imagine right now that you desire is something along the lines of:


object myobject
  x dword ?
  y dword ?
  z dword ?
  proc foo
    ; do something
    ret
  endp
endo

bar myobject ?

; and then, elsewhere

  call bar.foo
 



Am I correct?
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

u

The macro-models for OOP are merely a way to easily define classes, and easily initialize/handle objects from these classes. You can do the same without any macros. For the same reason, you can do OOP in C, it's just that in C++ it's easier, automated by the compiler. OOP is usually everywhere in your code, even if you don't realize it. When your current project becomes more and more complex, it becomes evident how you (smartly) organize things in OOP manner, even if that wasn't your clear intention.
The simplest way to see if you've done OOP code is: "if there a struct, and there are at least 2 procs to compute the struct's data, then this struct is an OOP class alright".
Coding in pure OOP or anything near it, is something you must never do! I've seen promising coders get entangled by it, after reading their first book on programming - C++ or Java. And then take 6 months to write code, that they would otherwise write for 6 hours.
With enough programming experience, you can easily see how and where to combine the strengths of: 1)procedural programming, 2)structural programming (has nothing to do with STRUCT! ), 3) functional programming and 4)object-oriented programming.
Please use a smaller graphic in your signature.

Klod

hi Rockoon

QuoteOOP doesnt really keep code and data together....
Yes your right,

what I had in mind was somthing like this:
_COLUMN struct
_initialize fastcall initialize                      ;constructor,would like to prototype frameless proc with type checking for fastcall with parameters
_delete PPROC@4 offset delete           ;destructor
_COLUMN ENDS

COLUMN struct
pos        dd ?
width     dd ?
hight     dd ?
backcolor dd ?
rowName db 32 dup (?)
m PTR:_COLUMN    ;pointer to struct containing proc addresses
COLUMN ENDS

then calling with something like:
mov eax,COLUMN.m
call [eax]+_COLUMN.initialize

I got the idea from:

object struct
var1 dd?
var2 dd?
funcs struct<>              ;this will cause bloat  -----> pointer to second structure
data ends

funcs struct
_func1 PTR func1
_func2 PTR func2
funcs_ ends

mov object.var1,100
call object.funcs._func1(whatever, parameters)

Ihave attached some experimental code. It got butchered because I tryed to implement type checking for procs and pointers and got quite lost in the process but I hope it will better illustrate what I'm trying to do. The key thing is to arrange data and functions in such a way that that accessing data and excecuting functions syntax is as simple as possible.



[attachment deleted by admin]

Rockoon

In a "fully" OOP model, you need that "boated" pointer to a list of function pointers.. this is because the consumer of the object may not initialy know its class..


When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

Klod

Hi Ultrano
Your post got posted while I was composing my reply to Rockoon. Thanks for your reply, very inspiring.
I originally was going to program in c++ and oops. I even worked through a book on oops. I was quickly turned off by the complex abstraction.
I had a hard look at ATC, played around with the examples, tried to decipher the macros (way over my head). It appears to me that most of the macros deal with symbol manipulation (name mangling) to work around the problem with duplicate definitions, Masms syntax checking and for the purpose of interfacing with C++ classes and Com. Also, OOPs data "hiding" looks like an oxymoron to me from the view point of  asm programming.
QuoteCoding in pure OOP or anything near it, is something you must never do! I've seen promising coders get entangled by it
This is definitely true for me, I'm not even a promising coder, just an enthusiast.
I should have worded my question differently, as I should not have mentioned the buzz word OOP, since this horse was flogged to death to many times. At the lowest common denominator, every programming scheme devist by programmers has the same function and purpose, namely to control the flow of code and data with interaction of the user. Maybe the term interface would be more appropriate.

Here is a problem, that I run in time and time again. I implement a solution into code, data structures, gui and whatever else and bugs. shortly thereafter, something changes, maybe the data structure needs to be drastically changed or the gui and then... start all over again.
Although this is the natural way of evolution, I would like to create a more modular coding style.
For lack of a better word, a modul. It contains everything needed to manipulate the data, resources and the interface. It also should be able to connect with/interface with other moduls etc.
Sounds OOP'ish?
Regards Klod

Klod

Thanks for your reply, Rockoon
I do not intend to build a full oops model.

u

Organizing your code into modules - you've found the solution yourself  :U
Here's an OK-example of mine, how a project, 1/3 the size of Quake3, is "structured":
[img=http://img219.imageshack.us/img219/9272/workspacepw0.th.png]
The Game.h  file contains: 1)equates 2)global structs 3)definition of "extern" variables 4) definition of exported module-functions. Entries in each of these 4 categories is grouped by module. Also, there you should put some visual markers when you group definitions - with a short explanation of the grouping. To see a complete example, see sDraw.inc  from the first post at http://www.masm32.com/board/index.php?topic=6514.0  .
Avoid having too many .inc files (i.e, avoid the general usage of each .asm file having 1 .inc file:  sprites.asm + sprites.inc). Having all definitions in one or two .inc files is best, in my experience.
Additionally to that module-grouping, in each file do more grouping - optionally. When you use "code-folding", and group folded procs, everything looks much neater and pleasant. Boosts morale. "Code-folding" (where you can hide/show a proc from the current file) is a must. When you are coding some proc, hide all other procs, that you won't be currently using for a direct reference. This is a way to avoid the innate fear of "breaking the current functionality of the app". This fear is what can really make you pause development for a week or more.
Also, do complete back-ups of the project everyday or on every milestone (or whenever you feel like having made a breakthrough). Not so much as to easily revert or keep your data safe... but to think in a clear mind that it's safe to make the project even bigger :).

These are probably the basic rules of making a big project. The rest is up to your personal style or the quest of searching for that style. And having fun during the journey  :toothy .
Planning the project well and taking decisions on the design/workflow are skills, earned during the development of big projects. The stronger the "boss", the faster you gain XP  :U
Please use a smaller graphic in your signature.

Klod

Thanks Ultrano for your suggestions.
I downloaded the sDraw1.2.zip file. Impressing stuff.

regards Klod

daydreamer

I recommend use of those macrosets, even minimum usage of its macros make you gonna use some C++ stuff in masm straight away without need to reformat to REAL4, REAL8 etc, but simple usage of FLOAT instead
whole sections of DX examples/tutorials is usable just by copy/paste or if you happen to have DX code already in C++ you wanna translate to masm