Page 1 of 3 123 LastLast
Results 1 to 40 of 89

Thread: the guru-test: analyze code

  1. #1

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Lightbulb

    This code in a public classmodule:
    Code:
    Friend Static Function Useoffset&(Optional offset& = -1)
    Static temp&
        Useoffset = temp
        If offset >= 0 Then temp = offset Else temp = 0
    End Function
    tell me where this could be usefull. If you guess correctly what i'm using it for (and note i can't find another better way to do than this) 10 points, find another usage for it 6 points and bonus 5 points if you find a better way to do it.
    Note every single keyword has to have it's purpose.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Is it part of Kedapak?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    No idea where you could use that...

    Code:
    Friend Static Function UseOffset&(Optional Offset& = -1)
        Static Temp&
        
        UseOffset = Temp
        
        Temp = IIf(Offset < 0, 0, Offset)
    End Function

  4. #4

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Nope, it's not part of kedapack
    Immediate if's are ugly, at least from what i've heard.
    Why optional? As a hint, there's one usage which is done with two calls.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    Code:
    Code:
    Friend Static Function Useoffset&(Optional offset& = -1)  'declaring a freind static which means that the variables do not interfear with the rest of the code
    Static temp& 'declaring a temporary value which will expire
        
        Useoffset = temp 'the value 'USER OFF SET' is equal to the temporary vaue
       If offset >= 0 Then  'if its greater thenor equal to 0 then
            temp = offset ' temp is greater thenor qual to 0
        Else temp = 0 ' if its under then-1 thenit is set to 0
    
    End Function
    
    
    I'm guessing thing would be useful in solving some sort of math equation.
    Last edited by dimava; Feb 24th, 2001 at 11:19 AM.
    NXSupport - Your one-stop source for computer help

  6. #6

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    keep guessing :)

    math equation? hahah ok keep guessing, if you get close i'll give point

    Friend means procedure is only accessible inside project, Static Function mean its shared for all objects of that class, static declaration does not expire due to procedure scope, but isn't accessible as module scope either.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    here's another guess:

    It does absolutly nothing
    and is used to crash the computer
    NXSupport - Your one-stop source for computer help

  8. #8

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    eh, nope it's not contradicting itself
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    I think

    Temp is a Number holder that could be reset by Calling
    the Function without a Parameter
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  10. #10

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    Active got a point.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    A wrappable, resettable counter?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    could this be used to validate numbers?
    NXSupport - Your one-stop source for computer help

  13. #13

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I just have to give a point to parksie althought it's not it's ultimate purpose offset actually is a counter, and is being reset at times. But why all these specifics?

    Note the calls are done in pairs.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    are you validating a serial number
    NXSupport - Your one-stop source for computer help

  15. #15

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Nope, this code has one purpose, and parksie revealed some of it
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    making your own 'timer'?
    counting items in arrays?
    NXSupport - Your one-stop source for computer help

  17. #17
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    is it?
    NXSupport - Your one-stop source for computer help

  18. #18
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Do you call it like this?
    Code:
    whatever = Useoffset(Useoffset + SomeValue)
    Or

    Code:
    whatever = Useoffset(SomeOtherFunction(blah))
    where SomeOtherFunction can call Useoffset?

    Perhaps it's used to count the level of recursion in functions that call each other.
    Harry.

    "From one thing, know ten thousand things."

  19. #19

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    dimava and harry: nope, another guess?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  20. #20
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    is it always called in pairs? It could be used to retrieve a new offset and store the old offset, then later used to get the old offset back again, but it would need to be initialised first.

    Perhaps the offset that gets passed in the second time it's called is incremented from the value returned by the first call.
    Harry.

    "From one thing, know ten thousand things."

  21. #21

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    okok, Harry get's a point, but it's actually the other way round, you pass the value to retrieve it later, but since if you look it in another way, you could interpret it as returned and passed, and it actually is incremeanted between the calls. And also, yes this is used within a recursive procedure.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  22. #22

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Honeybee get's 2 points for a very detailed analysis And yes, the parameter is passed the first time and not the second time, which is the purpose of optional in this case. There are several instancec of the class too.

    Honeybee get's a third point for noticing i could replace
    If offset >= 0 Then temp = offset Else temp = 0
    by
    If offset > 0 Then temp = offset Else temp = 0
    cleaver but there's no actual performance gain since both comparations takes one cpu cycle.

    As i've already said, it is called in pairs, and it's only used for this purpose, and it's called in combination with recursion (itself selfevidently is not recursive)

    As a final hint, there's a keyword involved that should lead you to the 10 points.

    Honeybee 3 points
    Harry 1 point
    Parksie 1 point
    Active 1 point
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  23. #23

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Gamerelated? honeybee you knew i was working on a game, and this actually has, but the snippet is part of a scripting editor and gamedata file compiler, so it's not about moving objects around the screen but allocating space for data
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  24. #24
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    My code is shorter ... Do I get a point now?

    Code:
    Friend Static Function UseOffset&(Optional Offset& = -1)
    	 Static Temp&
    	 
    	 UseOffset = Temp
    	 
    	 Temp = IIf(Offset < 0, 0, Offset)
    End Function
    
    'Code improved by vBulletin Tool (Save as...)
    *hehe* okok, IIF is much slower BUT: my code is shorter *g
    Last edited by Fox; Feb 25th, 2001 at 06:24 PM.

  25. #25

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Okay Fox, you get a point for testing and prooving Immediate if's are slower than you thought (that means slower than if statements). Actually it looks way shorter and cool, so you get the point for that, and it has cool vb-colors too, but no extra bonus points for that
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  26. #26
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Damn no points for the colors

    *g*

  27. #27

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Another very detailed report Okay i'll give you another point for that, but this time you you weren't as lucky as last time. The first time it's called, it doesn't handle the return value at all:
    Useoffset offset
    Negative value validation is of no importance either, It's only for avoiding the default value -1 since it's the first negative value i choosed it by default as default value. only 0 and positive values are passed to the function. Api calls are not involved either, except copymemory in the recursion. Okay for you and other's, there are still points to collect, even if you don't hit the 10 points, you can still beat Honeybee, with his 4 points
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  28. #28
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    Kedaman - you're keeping count of the number of objects created in a control array or the number of instances of an object and use the offset to determine if there are any left. Complete shot in the dark.
    That's Mr Mullet to you, you mulletless wonder.

  29. #29

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Good guess, although no luck. I was considering give you the 6 points for another usage, but since you could simplify that by passing the offset to a counter instead it's no points, close though
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  30. #30
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    What about if I simplify things by saying that you don't need to declare the Temp var. as static because the whole function is static so it's value would be kept anyway. Just dim Temp& would do it. Must be worth a few points.
    That's Mr Mullet to you, you mulletless wonder.

  31. #31
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    Clues so far :

    1. It's part of a class
    2. It's not part of the public interface
    3. It's holds a reference of some type

    A reference to the object instance in which the code is running ? The friend bit allows other objects which include your class to reference the ID so it would become a kind of object handle ?
    That's Mr Mullet to you, you mulletless wonder.

  32. #32

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    3 points.

    Yes, i knew, actually i discovered about Static modifier for the function was not a actual modifier, but declared all varialbes static automatically, but instead of mentioning it i waited for someone to notice it 1 point for that. The problem was solved easily, the recursion needs the reference object to be passed, so that you can call it from there. 2 points for hitting me right there. No the offset is not the handle, it's as said passed with the recursion, Friend is not used in that sense either. That was pretty close Paul, much is now revealed so anyone could easily get the 10 points now
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  33. #33
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    You're using it to create a call stack which you can collapse gracefully ? Useoffset is used to store the child process ID which is kicked off. Then if the object which created the child is terminated it can remove the child before closing neatly thus avoiding memory leaks ?
    That's Mr Mullet to you, you mulletless wonder.

  34. #34

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Whoa, you have ideas. i'm not doing anything in that direction, but if you elaborate it a bit convicing me you could use it for this purpose, i'll give you the 6 points. All keywords have it's purpose, except the superfluous Static modifier
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  35. #35
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    Ok but it'll have to wait until tomorrow now. See you then.
    That's Mr Mullet to you, you mulletless wonder.

  36. #36

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    hmm not really honeybee, could you explain how you think it all fits together?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  37. #37
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    To clean things up:

    its used in a class module
    if you call the function with no parameter you get 0
    its stored to be used later
    its a couter that can be reseted

    does this have to do with the High Score part of the game?

    guess 1:
    somehow validating if the player did what they were supposed to, and if so, then they get a point, which would be stored, so when they get another point, the points would be added

    guess 2:
    stores the file name?

    guess 3:
    random number generator

    I am positive it has to do with numbers
    NXSupport - Your one-stop source for computer help

  38. #38
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    It's something to do with finding data in a file where the starting position to read from in the file is dependant on the length of the previous item of data in the file. So each time you read in a data structure you set the new offset for the next read.

    Or

    The offset is the length to read in when you don't know the length of the data coming in, and you get the length from a header of some description.

    Closer?
    Harry.

    "From one thing, know ten thousand things."

  39. #39
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    kedaman, it's obviously not a counter, you must be using it to store a value which a friend looks at and uses. Therefore it must provide that friend with a piece of information which relates to the object itself. It returns 0 if it has never been set but some number if it has.

    Therefore the object (A) must put a value into offset so that object (B) can read it. The name offset might mean that it is some kind of memory pointer to something which A has created and B wants to access.

    Is that worth any points ?

    Going back to what I said yesterday you could use this routine to create a linked list of objects with Temp holding the name of the parent object. When the parent object is removed from the list then all children who have the parents name in Temp also get unloaded. You could create a tree structure with each node holding an object. Might be useful for mapping documents ( which contain many sub-documents ) or directory structures with each node a document or directory full of details and capable of running methods against those docs/dirs.

    Just a thought.
    That's Mr Mullet to you, you mulletless wonder.

  40. #40

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ok dimava, you get a point for most amount of guesses , but no more points for similar approach, yep it has to do with numbers, if you guess a couple of more times you maybe hit something..
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width