Wednesday, June 18, 2008

A disruptive technology for code generation

OK, now I have to support my claim. Here we go.

I've been using StringBuffer.append() for code generation (like everyone else) while looking for safer alternatives (safer meaning, compile-time type-checked). I've seen all the model-to-text languages. But the rest of this post is not about them.

One way to ensure syntactic validity when generating source code relies on instantiating EMF classes that stand for Java source elements. Verbosity can be reduced using fluent interfaces instead of directly invoking EMF factories, as reported in http://bugs.eclipse.org/234003

But problems remain. Another (perceived?) problem of AST-to-AST is the laborious coding of visitors, pattern matching and rewriting, multi-stage AST transformations, yes, model transformations. As usual, DSLs have been proposed to solve that, too. They are DSLs, i.e., another language to learn. You want to learn them? This way please.

But LINQ is on the march, and it's being used for code generation. It's being used to query the input (which can be even C# API elements, using LINQ to Reflection) and it's being used to piece together the resulting code:

As the ultimate test of suitability for AST-to-AST, LINQ is being used to refactor (refactor!) C# ASTs, no less. Compare with the article Unleashing the Power of Refactoring (and that article does a great job of explaining the JDT API for refactoring, so the comparison is *not* biased toward LINQ)

LINQ is not a DSL, its declarative constructs are based on logical commonalities in data access, better factored than those of model transformation DSLs. To my (informed) taste at least. And you're always free to extend LINQ with operators of your own, in a type-safe way that is. Or perhaps what finally convinced me were all the optimizations performed out-of-the-box when evaluating LINQ:

It's a pity we have no Java-based library to execute LINQ queries, queries expressed as ASTs (remember http://bugs.eclipse.org/234003 ?) although dedicated textual syntax would be nice, too. All right, all right, even if you'll settle only on textual syntax there's an interim solution till Java supports lambda expressions.

There's also talk about "LINQ in Scala". What I say is: it's not about syntax! (that's the easy part in fact) What makes a BIG difference are the optimizations supported by the engine when evaluating LINQ queries, input syntax notwithstanding.

If the above strikes a chord with you, let's join forces! I want to get rid of StringBuffer.append()! One of the grassroots movements to implement LINQ in Java is http://groups.google.de/group/jlinq and with some luck we won't need to wait for Java 7+ to enjoy the benefits of language-integrated queries.

P.S. If you need to convince your university department that the above qualifies for a master thesis, just flash the following papers and they'll accept immediately:

(you could also slip in one of my papers ;-)

Of course there are other opinions on best practices around code generation. But I hope you'll be reminded of LINQ when tracking down some obscure bug due to StringBuffer.append() in your favorite template language :-)

Miguel
http://www.sts.tu-harburg.de/~mi.garcia

47 comments:

pbsl said...

thanks for sharing this site. there are various kinds of ebooks available from here

http://feboook.blogspot.com

美麗 said...

Gods mill grinds slow but sure........................................

GarthStich said...

一葉晴貼圖百分百成人圖片台灣色情網摯愛中年聊天室正妹自拍0204視訊交友交友菁英1對1交友菁英1對1av色情影片一葉晴貼圖情色小說台灣色情網視訊聊天正妹自拍交友菁英1對1聊天室正妹牆自拍貼圖片區視訊交友百分百成人圖片

qqq said...

培養健全孩子最好的方法是父母先成為健全的人。.........................

咖啡機 said...

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull, Some have weird names , and all are different colors, but they all have to live in the same box.............................................

Research Writer said...

this kind of blog always useful for blog readers, it helps people during research. your post is one of the same for blog readers.

Thesis Papers Writing

天天影片 said...

請繼續發表好文!加油加油再加油!........................................

宴神 said...

臨淵羨魚,不如退而結網。 ..................................................

寧年 said...

一切與生俱來的天然贈品,時間最為寶貴..................................................

依政琦萍 said...

TAHNKS FOR YOUR SHARING~~~VERY NICE.................................................

TommyStark0109佩政 said...

Haste makes waste.......................................................

IdellaD_Bar3321 said...

裸照裸女愛愛無碼尋夢視訊聊天a漫a片a圖一夜情一葉情人妻激情情色寫真美女自拍辣妹自拍正妹自拍美女走光辣妹走光正妹走光脫衣秀脫衣走光色情自慰自拍成人全裸打炮打手槍打飛機巨乳巨奶女優大奶

志文 said...

ut聊天77p2p85cc85st85街視訊視訊聊天ava片a片下載成人情色色情影音視訊聊天洪爺影城洪爺免費視訊免費a片免費一對多utsogo論壇ut聊天室成人片免費看................

蘇pet0701em_halvorsen said...

大奶妹貼圖區0204性影片觀賞露點自拍淫婦女生如何自慰色情站成人笑話av激情網愛視訊美女淫蕩av成人色情電話辣妹視訊聊天性關係情色vcd自慰圖淫美成人論壇台灣色情論壇成人聊天室自拍裸女貼圖視訊成人免費a片影片av成人網成人色情色情台灣辣妹小穴太太陰毛色情訊息裸女自拍色情影片a片論壇性愛技巧美女脫胸罩情色天堂av寫真色情視訊聊天做愛視訊成人影片床上戲情色聊天網火辣情色台灣女優性愛秘笈台灣av女優手淫自慰影片

育偉倫航 said...

君子如水,隨方就圓,無處不自在。 ..................................................

佳喬 said...

仇恨是一把雙刃劍,傷了別人,也傷了自己...............................................................

侯郁順 said...

成人85 高雄視訊 土豆聊天室 無碼影片 交友 av女優 性感脫衣遊戲 脫衣影片 偷拍貼圖 聊天室小高 女女愛愛圖 免費觀看情趣影片 18禁免費 少女自拍貼片 免費影城 成人a片 情色 av色情片 一夜情 383影城 視訊聊天室 玩美女人 美女 辣妹 人妻 熟女 免費視訊 視訊聊天 a圖 寫真a片 885cc 線上成人 嘟嘟 影音視訊 自拍貼圖 找援交妹 情人聊天室 免費脫衣舞短片 av色情片 洪爺影城 大奶 sex 成人電影下載 巨乳影片 性感制服 後宮電影院(入口) 限制級 裸體0204影片 性愛免費觀賞 歐美模特兒走光

DennyR_Guari佳穎 said...

朝著既定的目標走,就不會迷失。........................................

said...

人生最大的榮耀,不是永遠不敗,而是屢仆屢戰........................................

采瑩采瑩 said...

才華在逆境中展現,在順境中被掩藏。 ....................................................

benjaminga said...

「不可能」這個字詞,在聰明人的字典中是找不到的。........................................

MinB2139 said...

Better say nothing than nothing to the purpose...................................................

建月 said...

Man proposes, God disposes...................................................................

彥霖 said...

很喜歡你的部落格 留言支持你 祝你人氣長紅~~~......................................................................

木堯木堯 said...

在莫非定律中有項笨蛋定律:「一個組織中的笨蛋,恆大於等於三分之二。」......................................................................

建彰建彰 said...

所有的資產,在不被諒解時,都成了負債.................................................................

美方 said...

當一個人內心能容納兩樣相互衝突的東西,這個人便開始變得有價值了。............................................................

dawsonfelicia張君dawsonfelicia均 said...

向著星球長驅直進的人,反比踟躕在峽路上的人,更容易達到目的。............................................................

亦妮 said...

要照顧身體歐~保重..................................................................

于倫 said...

海鷗要高飛,必先遠退。花蜜要香醇,必先久釀。............................................................

吳婷婷 said...

沈舟側畔千帆過,病樹前頭萬木春............................................................

致念致念 said...

新手上路哦~請大家多支持^_^..................................................................

胡茹雨胡茹雨 said...

我們老得太快,卻聰明得太遲。..................................................

香昱信張君林 said...

不費勞力而得者,唯貧困而已................................................

思恬 said...

不妄求,則心安;不妄作,則身安!......................................................

張俊明 said...

生存乃是不斷地在內心與靈魂交戰;寫作是坐著審判自己。..................................................

邱允成邱允成 said...

婚姻對男人來說是賭他的自由,對女人而言卻是賭她的幸福。.................................................................

賴成貞陳韻邦 said...

希望能有更多心得與我們分享~ ............................................................

家唐銘 said...

良好的開端,已是成功的一半。..................................................

黃子黃麗旺軒 said...

愛情不是慈善事業,不能隨便施捨。.................................................................

淑張福 said...

愛情是盲目的,但婚姻恢復了它的視力。......................................................................

王辛江淑萍康 said...

要持續更新下去喲!!期待~~............................................................

1615 said...

世界上沒有本來就應該的事,因為老天爺也沒有劇本..................................................

文岳仲君 said...

看著你的BLOG 好多朋友都回應 真厲害..................................................

惠NorrisBradwell041花 said...

你文章很棒的~繼續分享給大家~~~~..................................................

159fsaf said...

喜歡你的部落格,留言請您繼續加油............................................................

孫邦柔 said...

祝大家都平平安安健健康康!............................................................