儘管 C++0x compiler 還未成熟與普及,已有工程師把弄新的語法,創造耀眼花招。
其實我也非常喜歡耍玩語法上的把戲,但我亦知道它會帶來什麼災害。
以下文字引述自花招裡的一篇回覆,也是我心裡想說的:
Interesting acrobatics, but I am a KISS fan.當然,流行/藝術派與實際派的存在都是有意義的;否則編程世界不是一團糟就是停滯不前。
I prefer not to mandate a C++ black belt (with several Dans on occassion) on coworkers who try to understand and modify my code, so thanks but I'll pass.
Is there anything in the above code that cannot be done in plain C in a way that 90% of the dev population can understand and 80% can modify/extend without a mistake?
Why do architects feel so compelled to save the world by providing infrastructure and plumbing for everything conceivable under the sun?
What about memoization? If I am in such a corner case where caching the results of a function call will *actually* improve performance, what makes you think I would opt for an obscure and totally incomprehensible generic template that I cannot understand or debug, rather than a custom-tailored, totally non-reusable, top-performing, totally understandable and debugable solution?
Don't get me wrong, I am not an anti-STL, do-it-yourself (CMyHashTable, CMyDynamicArray, CMyOS) gangho. I am just a KISS fan (including the rock band). If something can be done in a way that is simpler, easier to understand, debug and extend, then I prefer the simpler way.
I just get so frustrated when people do all this acrobatic stuff in production code just because (a) they can do it (b) it's cool to do it, without thinking back a lil'bit or actually having mastered the 'tools' they are using.
A similar example is 'patternitis'. I have seen countless C++ freshmen reading the GangOf4 Design Patterns book and then creating a total mess in everything, like deciding to implement the Visitor pattern on a problem that required Composite and ended up coding a third pattern alltogether from the same book, still naming the classes CVisitorXYZ (probably they opened the book on the wrong page at some point).
I have met exactly 1 guy (I called him the "Professor") who knew C++ well enough and had the knowledge to apply the patterns where they ought to be applied. His code was a masterpiece, it worked like a breeze, but when he left, none else in the house could figure things out.
So what's the point with these Lambda stuff really? Increase the expression of the language? Are we doing poetry or software? Why should we turn simple code that everyone understands into more and more elegant and concise code that only few can understand and make it work?
I have been coding in C (drivers) and C++ for 15 years and not once was I trapped because I was missing lambda expressions or similar syntactic gizmos.
So what's the point really? Please enlighten me. I don't say that *I* am right and *YOU* are wrong. I am saying that I don't see, I don't understand the positive value that these things bring in that far outweighs the problems they cause by complicating the language.
我也認同你的想法。對於 C++0x 裡那些炫麗高深的技巧,到底能夠為程式設計者帶來多少益處?我們都需要更多的時間與應用實例來說服自己。
回覆刪除在全盤接受這些新玩意兒前,我會盡可能保持 KISS 原則!
這篇正好呼應你的部落格名稱哩。 :P
謝謝你的回應阿!
回覆刪除簡練優雅的設計,豐富與簡約的平衡是我接著要實行的目標。
至少要會 這招.
回覆刪除