0

We have an engineer on our team that would like to the do the following inside of JSON data:

"visible": "$(= state 'state_c')"

Now in the model he has the following method to determine the state:

protected function getCurrentState():String
{
   var state:String = "defaultState";

   if (xxxx)
      state = "state_A";
   else if (xxxx)
      state = "state_B";
   else if (xxxx)
      state = "state_C";
   else
      state = "state_D";

   return state;
}

Now elsewhere whenever I need to update the state I would call the following:

data.state = getCurrentState();

The notation used in JSON data is in prefix notation (LISP) in case you were curious. The code where the model exists is written in AS3 and the object named 'data' above is that of type Object.

I am against this idea and I don't understand the value of putting logic into data. I have never seen a paradigm that would be used this way. I think this breaks the MVC architecture design and introduces many different problems. Here are my biggest issues with this design:

1) All the logic is type unsafe (data is type-unsafe)

2) Now the developer must know how to do three separate things to complete a task (write the programmer portion of the JSON data, write the correct prefix notation, and put correct logic in code)

3) I don't see a good way to unit test this behavior

4) Spreads logic into multiple areas of code and thus will make finding an error more difficult.

I am looking for any opinions on this matter. Why would this be a good idea? Are my reasons for disliking it valid? Is there some value I am missing?

tereško
  • 58,060
  • 25
  • 98
  • 150
ShaffDaddy
  • 63
  • 1
  • 9
  • First of all this will probably be closed for being "primarily opinion based". Second, I'm not connecting the parts here. The `getCurrentState` function looks fine. Using `data.state = getCurrentState()` where `data` is `Object` instead of a class with `state` property is not a great idea IMO. But what does these things have to do with the funky `"visible": "$(...)"` code? How are they related? Is there some AS3 code that parses that expression and compares it to `data.state`? Where is that code? What does it look like? When is it invoked? – Aaron Beall Mar 24 '16 at 16:06
  • Yes I realize this was primarily opinion based, however I was looking for any validation one way or the other. The funky code is related because it would change the visibility based on what state you have changed in the AS3 code. There is AS3 code that parses the expression. That AS3 class parses data whenever it is received and places it a typical data model. The data model is where the currentState function exists. Does that help you understand the issue better? I still strongly believe that is a bad design decision for the all reasons above – ShaffDaddy Mar 24 '16 at 18:25
  • Yeah it's a good discussion I'm just giving you a heads up that SO doesn't like opinion-based questions. Personally I don't have a problem. In regards to the code design, I agree there are all sorts of problems like the ones you've stated. IMO writing a custom string parser is not a good general purpose way to use a language (JSON and AS3 in your case). JSON is a data transport, AS3 is a programming language, the logic should be in AS3. Good luck. – Aaron Beall Mar 24 '16 at 18:46

1 Answers1

-1

All of your arguments are the right ones. I won't go into specific details here, because all of the same arguments for not using eval apply and have been extensively discussed.

Community
  • 1
  • 1
Quotidian
  • 2,870
  • 2
  • 24
  • 19