Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Questions about generation code for Objective C and small games for iPhone
icon12.gif  Questions about generation code for Objective C and small games for iPhone [message #900578] Tue, 07 August 2012 15:54 Go to next message
Ricardo1980 Missing name is currently offline Ricardo1980 Missing name
Messages: 11
Registered: November 2011
Junior Member
Hello out there!

I'm new to M2T and have some questions. I'd like to create a system to create simple iOS games (something like interactive ebooks for children). I already have an idea of my required metamodel and diagrams, but I have some questions regarding code generation.


I'm reading about different M2T tools: Acceleo, Xtend, CommentTemplate, Xpand and Mofscript, but actually I don't have real experience and all this stuff is new to me. So I'd like to know your opinions about which one could be better for this project. Let me know your ideas.

The code I want to generate have to use cocos2d as a 2d engine, and evidently Objective C as a language. Because of this, ARC (automatic reference counting) cannot be use, so I have to manage the memory manually, using retain and release. Is this a problem with code generators? I ask this because usually they usually generate Java, where memory is managed automatically using a garbage collector. Is this a problem for some code generators?

Another question I have is, when you generate code, do you also generate project files?
I mean, when using Xcode for creating a project, a file (package) .xcodeproj is created, that has a XML file with all .h and .m files for compiling the project.
Do you usually generate this kind of configuration files with M2T, or just generate a command line to compile all generated files?
I see a MDD project for the iPhone called iPhonical that it seems generates a full iOS program and even launches the simulator from Eclipse, see the video in their website (I can't post links).


Thanks a lot for your suggestions, I appreciate it a lot.
Re: Questions about generation code for Objective C and small games for iPhone [message #900624 is a reply to message #900578] Tue, 07 August 2012 20:00 Go to previous messageGo to next message
Mirko Seifert is currently offline Mirko Seifert
Messages: 31
Registered: July 2009
Member
Hi Ricardo,

you'll need to make sure that the generated code implements the memory management correctly. None of the mentioned code generators with do that for you. Neither will one of these tools prevent you from doing this correctly.

I'd suggest to create all textual artifacts using a code generator. This way you can use the same tool for the same task. Using a command line script just introduces additional complexity. Moreover, the project files, headers and so on do usually contain stuff that depends on your model.

The only thing I'd not create with a (M2T) code generator are binary files. For this you need a Model-To-Binary tool Smile

Cheers,

Mirko
Re: Questions about generation code for Objective C and small games for iPhone [message #900639 is a reply to message #900624] Tue, 07 August 2012 21:48 Go to previous messageGo to next message
Ricardo1980 Missing name is currently offline Ricardo1980 Missing name
Messages: 11
Registered: November 2011
Junior Member
Hello Mirko, thanks for reply.

Whe you say: "I'd suggest to create all textual artifacts using a code generator. This way you can use the same tool for the same task."

What do you mean exactly?
Perhaps you mean use a generator for source code and the same for a command line or script, instead of another one, isn't it?
As far as I know, as textual artifacts I only see code and building script. Well, documentation can be one of them, but in my project no docs are generated.

Thanks.
Re: Questions about generation code for Objective C and small games for iPhone [message #901531 is a reply to message #900639] Mon, 13 August 2012 09:16 Go to previous message
Stephane Begaudeau is currently offline Stephane Begaudeau
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

Most of the generic code generators (Acceleo, Xtend, CommentTemplate, Xpand and Mofscript) will work the same way. I don't know CommentTemplate but it seems to be similar to the other tools. You write some template that are composed of static pieces of code (in black in the following screenshot) and dynamic ones (in blue) that will use elements from your input model to compute the generated code.

http://help.eclipse.org/juno/topic/org.eclipse.acceleo.doc/assets/img/features/domain-free-ecore-gen.png

This implies that you have a model representing your code first. This model need to contain the concept that you want to represent in your code (you can define those concepts in a meta-model). It is easy to create a meta-model with the various graphical (ecore tools), tree based (ecore) or textual tools available (xcore).

After that, there are tools that can take your meta-model to generate the tooling matching the concepts defined in your meta-model to let you easily create models. You can generate in one or two clicks a text based tooling (Xtext), a tree based tooling (ecore), or even a form based tooling (EEF). You can also create a graphical tooling for your meta-model but I think that it's a bit more difficult with tools like GMF or Graphiti.

When you have your meta-model and some instances (models), you can generate code from those models. You could also use an existing meta-model as your starting point like UML (which contains familiar concepts like classes or interfaces) but with a custom meta-model you could directly manipulate the concept of your domain. For an iPhone application, you could use concepts like Views or Buttons, this way your tooling generated could let you manipulate familiar concepts instead of having generic programming concepts. It could also help you to create more powerful generators. For example, if you need ten classes to create one complex view in your application, you could use ten instances of the concepts Class of UML and then create a code generator that take an instance of Class and generate a good old Objective-C class. If you defined a concept ComplexView then you could create a generator that takes a ComplexView and generate the ten classes at the same time. If you need to have dozens of those complex views, it is easier to manipulate your model.

You can see here a small domain specific language created with Xtext for Android applications that let you manipulate Android specific concepts directly:
application "My First App" => org.xtext.example.droid.myfirstapp

screen Welcome { }

screen Main { }

More about this DSL here.

The generic code generators that you talked about will all require you to write the template necessary for the code generation. One code option is to start with a prototype of the code you want to generate and then create a model representing this prototype and try to build the generator which, using this model, could re-generate the code of the original prototype. After that you can add more feature to your prototype, your meta-model and your generator.

Among the tools available to generate code, I would recommend Xtend or Acceleo (Full disclosure: I am the leader of Acceleo Razz) since they are the ones with the most serious tooling. Xpand is nice but I'm pretty sure that you can do with Xtend everything that Xpand does and more (both products are from the same company). As for the features of the generated code, well it only depends on the template that you will write. Is you look at the template generating Python in the previous screenshot, if I want it to have any kind of additional features, I'll have to write it by myself or I'll have to find someone who did it already. The advantage is that you can have the code generated exactly like you want.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo



[Updated on: Mon, 13 August 2012 09:20]

Report message to a moderator

Previous Topic:[XPAND] Update of XPAND Content Assistant when changing Metamodel
Next Topic:[Acceleo] Boolean operators in version 3.2
Goto Forum:
  


Current Time: Wed Oct 01 18:34:40 GMT 2014

Powered by FUDForum. Page generated in 0.01750 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software