The Way To Great

通往伟大的路

Flex编译器支持条件编译

Flex编译器支持条件编译


条件编译允许我们告诉编译器选择性的不编译给定一部分代码除非我们给定的特定条件满足才对该部分进行编译,显然这是在FLEX3中ADOBE刚刚推出的新特性,之前我都没有听说过,知道今天造成J.C.发给了我LIVE DOC上的链接。

你也许会想啊条件编译有什么用啊?我为什么要用啊?我不得不说条件编译非常有用,它使用于多种情况
【译者注:学过C的人其实都不陌生,条件编译对于调试非常有帮助,我们可以在调试版本里面插入大量的输出语句,而在发布的时候通过条件编译更不不需要删除这些语句,这是我个人的一点经验】

有没有写过大量的条件语句将静态变量开启和关闭?有没有写过在调试的时候才用到的方法?如果你熟悉C++那你总用过#IFDEF吧?如果有这些问题,那么你可以继续看下去

首先条件编译对于复杂的调试非常有用,有的时候你也许会自己写一些代码,这些代码通常能完成编译器的DEBUG程序不能显示给你的信息,为了不至于在调试完成之后,找到大量这些的代码并将其注释起来【需要的时候再开注释】,这个时候你就可以使用条件编译告诉编译器忽略目前的这些调试内容

第二为这段代码够将AIR 和FLEX两个版本的应用程序,假设你有一个非常有用的类你想将它编译成FLEX和AIR版本的,而AIR版本的可能需要额外多一点点的代码,那么你就可以使用条件编译来包含在这些代码,然后选择性的将其编译成AIR 或者是FLEX版本的程序

【我觉得讲到这儿就差不多了吧,条件编译可是非常有用的哦,想使用?那就赶快翻翻你LIVEDOC,打个标记吧】




Flex compiler supports conditional compilation

| | Comments (5)
AddThis Social Bookmark Button
 

Conditional compilation allows developers to tell the compiler not to include certain parts of their code unless a set of conditions are met. Apparently Adobe added this feature to Flex 3, though I hadn't heard anything about this until this morning when Jim Cheng sent me the LiveDoc link.

You might be wondering, why would I ever use something like that? Well, I'm glad you asked. Conditional compiling is incredibly useful in a few different situations, and chances are you're already solving some of the problems conditional compiling address the hard way. Ever flagged a section of your code with a big static variable to turn it on and off? Ever written a debug method you commented out later, or simply removed all the references to? If you're from the old C++ world, ever used #ifdef? If the answer to any of these questions is "yes" or "maybe" or even "no, but as a curious developer I'd sure like to know more!", then read on.

First, conditional compilation is useful in complex debugging. Sometimes you want to run a bit of debug code that tells you something a simple debug session won't. Rather than commenting this code out or flagging it with some sort of compiler variable, you can now code debug sections in to your heart's content. Just tell your compiler to ignore anything in the "debug" namespace and you'll be fine.

Second, it's great for building simultaneous AIR builds with your flex apps. Let's say you've got a class that's useful for both an AIR app and a Flex app, but the AIR app needs a little extra code, or includes a feature your Flex app can't support. Rather than reproducing all of the useful code or extending the class and overriding the methods in question, you can flag certain sections to only be compiled for AIR and ignored by Flex.

Third, it's useful for monkey-patching. Monkey-patching is a messy process that I don't recommend, but sometimes it's the best solution to a problem. In these situations it'd be nice to easily toggle on and off our monkey patched classes to see if they're working, how they're affecting the application, and hopefully remove them when Adobe implements the bug fixes we're undoubtedly patching around. :)

So check it out. If nothing else, by removing the need for commented-out debug methods or big static variable flags, conditional compilation will help you write cleaner code and earn you the respect and admiration of your co-workers.

阅读更多
个人分类: RIA
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭