views:

47

answers:

2

Hey All,

I'm writing a little scripting language just for a bit of fun and the learning of the codes :P

I would just like your opinions/suggestions. I have an idea but I don't want to include something that people are going to want to spit on. I plan on making this language open source once, soon.

Does anybody think that it would be cool to have something like:

[Foreach] Uppercase Letter s
          in Case-Insensitive Word SallySawtheSeafiShandateit:

          Count++.

          s.Highlight: True.

          RunOnce.ProtectedMethod.ActivateProtectedMethod: IsTrue.

[Protected Method.LockTo: [Foreach]].IsTrue
          StatusBar.Message: Match for s was found. Total: Count..
          RunOnce.ProtectedMethod.Disable.

Explanation: What the above actually does is it searches through a string of text "SallySawtheSeafiShandateit" and highlights every single match. But when it finds the very first match for "s", it runs a method called "IsTrue", and sets the statusbar text to "match was found...". And then deactivates the RunOnce method so it may no longer be accessed, since there's no need for it to be run again.

This might not be the best example, but I think you get the idea. There have been plenty of times where I've needed to do something only once in a foreach loop, but couldn't, without writing a whole bunch of other code.

I figure, atleast this way, everything can be done in just two methods.

Please be brutally honest. :)

Thank you

+2  A: 

This just seems like an over-complication of the following structure (in java style):

boolean ranOnce = false;
for (char c : string.toCharArray()) {
  if (c != 's') continue;
  if (!ranOnce) {
    // do stuff once
    ranOnce = true;
  }
  // do other stuff
}

It just seems like extreme over-engineering to me, when a single boolean and an if condition do the trick.

developmentalinsanity
Thank you developmentalinsanity. I agree with your point. :)
lucifer
+1  A: 

Hm. For this sort of situation I'd normally just use a flag variable and a conditional.

I'd reconsider "runOnce" -- it's a little ambiguous. Does it run the first iteration, the last iteration, somewhere in the middle? From what I can tell it looks like yours runs in the very first iteration, but then again what use would displaying the total count be in the first iteration? You'll know it's just "1".

For my money, I think I'd actually use two keywords that fired events/methods/etc at the first iteration and at the last iteration, respectively.

godheadatomic
Thank you godheadatomic. I agree with that. :)
lucifer
Glad to help :)
godheadatomic