Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

I'm trying to improve my code organization skill via design patterns (namely uFrame) but...

Discussion in 'Scripting' started by TokyoDan, Mar 23, 2015.

  1. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    I finished my game project but as time went on my code became increasingly harder to follow because I guess I lack design pattern discipline. Because of this I bought the uFrame asset in an attempt to learn and force on me better coding habits. But I have given up on uFrame because the tutorial is the worst I have ever attempted to follow.

    I heard that the free StrangeIOC is similar with a good tutorial but the Unity asset hasn't been updated in over a year.

    Is there another framework or asset that is for code organization or to help the programmer prevent spaghetti code by forcing the coder to follow a good MVC design pattern?
     
  2. bitcrusher

    bitcrusher

    Joined:
    Apr 24, 2013
    Posts:
    156
    strangeioc has an update coming, but if you can't understand uFrame, StrangeIOC might be more difficult for you, uframe eliminates a lot of the boilerplate code you need to write, and has a visual designer. There is zenject as well.
    https://strangeioc.wordpress.com/ for updated blog posts
     
  3. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    I get the feeling that StrangeIoC might be easier for me as the tutorials in uFrame were so bad that they led me in wrong directions or left me hanging. Also I got the idea that uFrame may be too complicated and overkill and for single developers because the uFrame guy told me this:

    "uFrame MVVM - The product you purchased, is somewhat of enterprise design model that has been used for developing applications for years. So there's a gap in the community with it, where is people who are familiar with this model pick it up super quickly."

    He also said this:

    "We have a new product coming soon called ECS that is much simpler and catered a bit more towards Unity Dev. When we release it I think you'll be happy with what it has to offer, and again i'm really sorry you've went through all this trouble. Your not the first which is why we want to relase uFrame ECS, it has a much easier learning curve compared to uFrame MVVM."
     
  4. bitcrusher

    bitcrusher

    Joined:
    Apr 24, 2013
    Posts:
    156
    iono, check out strangeioc yourself, maybe you will like it, or wait for uframe ecs.

    uFrame tries to emulate a lot of what is here(http://en.wikipedia.org/wiki/Model_View_ViewModel), for unity3d devs, that is what he meant by people familiar with enterprise design models. if your game is simple then it might not be worth it, but the more complex your game is, following a design pattern like that can be really helpful.

    also strangeioc has only a few tutorials as well, but here is one i found external to the strangeioc website
    https://coffeebraingames.wordpress.com/2014/03/05/getting-started-with-strange-ioc/
    GL!
     
  5. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Thanks bitcrusher. That tutorial will help a lot.
     
  6. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
  7. Galf

    Galf

    Joined:
    Feb 24, 2013
    Posts:
    27
    You deserve some praise for admitting to having unstructured code (and wanting to fix it), but are you aware of any particular reasons for *why* your code is painful to deal with? I'll admit I'm not particularly familiar with either of the frameworks you mentioned, but my impression is that you're looking at them for their MVVM/MVC architecture, which honestly might not be applicable to you (or easy to understand). For example, MVC stands for Model/View/Controller. For it to work well, you have to understand where each piece of behavior should fit into that -- does some particular piece of code belong as part of a model, a view, or a controller?

    If you're a novice to MVC, what typically ends up happening is that you just dump virtually everything into your controller, which makes the whole thing meaningless and just as unstructured as if you hadn't used MVC.

    I'm a little scared, because your initial post made it sound like, "Well, if I use design patterns, my code CANNOT be bad," which is very far from the truth. There is some push-back against design patterns, mainly because they can lead to mis-use. They are meant for solving common problems with a common vocabulary, but at their worst, you mis-apply (or mis-understand) a design pattern, overcomplicate your code, and confuse everyone with why a particular pattern was applied to something that didn't warrant it.

    Unfortunately there's no silver bullet. If you want better structured code, you need to understand what makes code good or bad first -- no asset is going to do that for you.

    If you're still interested, I'd recommend checking out some staples:
     
  8. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Thanks Galf.

    My code is painful because one thing calls something that calls something else which is also called from a few other places. Changing anything breaks something somewhere else, Therefore when I need to change something I now have to take hours to make a complicated flowchart of what is calling/being called, and from where. And it just keeps getting more complicated, especially when using an async library that depends on callbacks in my code.

    I know what all the MVC, NVVM, etc. stand for and I understand the concepts. I've done a lot of reading (Design Patterns by the gang of four). I just have a hard time applying those concepts to the real world...thus I failed at using uFrame which I though would force me to use the concepts correctly (I blame the incomplete tutorials). Now I'm trying StrangeIoC which is a bit more lightweight.

    Also I understand that following design patterns (or thinking you are following them) does not guarantee well structured or correctly structured code, especially if you are using the design patterns wrong because you don't really understand them.

    And I can always do some more reading. Thanks for the links.
     
  9. Galf

    Galf

    Joined:
    Feb 24, 2013
    Posts:
    27
    Hmm. On the one hand then, you might benefit from the IoC aspect of StrangeIOC more than the MVC/MVVM stuff, depending on how your code is structured. That allows you to rapidly replace one module's functionality with another, across your entire codebase (or a portion of it).

    On the other hand, what you're describing does sound a lot like spaghetti code, where maybe the module boundaries aren't clearly defined -- maybe certain classes are doing too much, or you have many classes that are doing something simple, but you don't have a logical-enough file structure so that the classes are clearly related to each other. It sounds like you have a ton of a side-effects in your code, which you need to keep track of when doing anything -- lots of global variables/Singletons?

    Good luck! :)
     
  10. wcorwin

    wcorwin

    Joined:
    Feb 7, 2014
    Posts:
    9
    Hey TokyoDan. I'm one of the owners of Strange. If you're getting started I'd love to get a little feedback on the documentation. We're doing a new release soon! I hope to improve some of the documentation for new users and figure out where we're weakest. We're also hoping to introduce a new example project that is a little more true-to-life. Asteroids isn't a great example project, to be sure. Community feedback is mostly experienced users so a new user's experiences would be useful to hear!

    Perhaps more importantly, check out the github project here for the most up-to-date version. For the newest docs check StrangeIoC docs We've fixed many bugs and introduced many useful features since our last (sadly, very old) asset store release.
     
    TokyoDan likes this.
  11. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Thanks. for the suggestions.

    I seldom use inheritance. I read some about Entity Component Systems and how inheritance is often overdone in OOP and that it is not suited to game development. So I try to take advantage of Unity's ECS style. Although I have many classes inheriting from MonoBehaviour and used as components on GameObjects. Most of them are only used once but I they are not singletons as they don't use the mechanism that prevents them from being instantiated more than once. I do have a lot of public variables so that I can easily assign their respective gameobjects in the editor inspector.
     
  12. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Hello wcorwin. That is the documentation I am following. I am using the StrangeIoC from Unity's Asset store. I'll ditch that and download the GitHub version. Thanks. And I never came across an Asteroids example. Is there one? I read The Big Strange How to and the myfirstproject example. The how to is easy to understand but I am still trying to get my head around the example. Understanding it is not a problem, but the real-world application of it to a game is. That's why I'm about to start on this example by Coffee Brain.

    I'd would be willing to pay for a whole well documented simple game project done in StrangeIoC which included project assets, videos and text explanation, or even just text explanation with no videos.

    Also because there are numerous classes/C# files that are used in a Strange app, I'd like to see more diagrams (lot's more) of how everything connects up and is related. It is very hard to get a picture in my mind of how things work by clicking back and forth between C# files in my editor.
     
    Last edited: Apr 7, 2015
  13. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    wcorwin. I found the Asteroids example.
     
  14. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    I am trying the StrangeRocks example. But when I run the game, in the game window the paths of the asteroids are not erased. Each asteroid leaves a trail.

    https://dl.dropboxusercontent.com/u/34724021/SR.jpg

    I tried running it in Unity 4.6.4 and 4.5.5 and it is the same in both versions.

    FYI. I also posted in the Google Group for StrangeIoC. Which is better to post questions about StrangeIoC. Here or on the StrangeIoC Google Group?
     
  15. wcorwin

    wcorwin

    Joined:
    Feb 7, 2014
    Posts:
    9
    Responded on Google Group. I hate to say one or the other, although the strange community is on the google group. Asking on both is probably the only wrong answer, if only because I have to respond on both or everyone thinks I'm ignoring you :)