Sponsored by Dragon Age: Origins
Can't get enough Dragon Age: Origins? Play the flash game. view!
DragonAgeJourneys.com - Play the free companion flash game to Dragon Age: Origins.
94 Comments
- officialchicken, on 10/12/2007, -1/+5LAME
"but you can also create objects that bend at runtime, creating new methods and member variables on the fly. You can't do that with the Java, C++, or C# languages"
This is a lie. - jayf, on 10/12/2007, -3/+5This is one reason I like Java actually.
Many of these web languages (yes I know PHP can do EXEs too) and wacky features made for them are designed for non-programmers (fighting the temptation not to call them script kiddies) who don't have the patience to sit down and actually "think out, grasp and understand" something properly in order to design it perfectly. If you have a class that needs redefining on the fly it means you didn't design it well enough in the first place. Normally I wouldn't be bothered by such an anomaly as this but the people who preach these languages are beginning to make an impact on the industry and I fear for the worse.
I'm amazed by what has happened in the last 5 years. The ratio of actual programmers and developers (people who love it enough to do it on their own free time) to non-programmers (people who used to work in a record store and saw an opening for a programmer in the paper and went for it) is falling rapidly. Add designers who think knowing Actionscript makes them developers to the mix and you see the problem. These people are amateurs with no real understanding of the inner workings of computers or the true art of development.
If this were the shoe business it would be like comparing an 80 year old Italian man who has made shoes since he was 12 and loves and understands the art and mechanics of feet to a recent hire at Nike's Manila factory making that plastic bubble that goes into every shoe with the word "air" on it. What they do is deceptively similar on the surface but digg deeper and you see the difference. One is art, a true devotion to understanding every aspect of the development process, the other is a mass-produced process where nobodies off the street instant foot smiths.
I am a member of the former. What about you? - joeolivas, on 10/12/2007, -1/+3Learn Lisp. Then realize the shortcomings of every other language in existance.
- SpookyET, on 10/12/2007, -3/+5What a load of BOLLOCKS! You can emit code in .NET in any language at runtime, and it works similar to this. You may be able to emit extension methods too.
RUBY supports this with a normal syntax, not those "call" hacks. That PHP code is ugly as hell and very complicated. No DIGG. - inactive, on 10/12/2007, -0/+2Tricks that Java/C#/C++ can't do? Those three languages are all general purpose, turing-complete programming languages capable of solving any solvable logic problem. When you look at this idea, the real question isn't whether or not other languages can do it, but ask what general problem the technique is solving, and how those other languages would solve the same problem.
There's also the question of the domain of the problem. Technically speaking, anything PHP can do, any general purpose programming language can do in an identical way because you could build a PHP interpreter using C++ and, using your C++ generated interpreter, you could then perform the same operations.
Of course that scenario doesn't take into consideration time or practicality. Faced any given problem, there's obviously a much easier way to solve it. Those who claim that any language can do anything that Java/C#/C++/Perl/Python can't is just selling you a line of bull. At best, a particular language may make the task easier or confront the problem more efficiently. I have never seen a single application built using any language that couldn't just as well have been done in any language. Heck, if the person is doing a good job developing, you shouldn't even be able to tell what language they developed their application with. - verucasalt, on 10/12/2007, -0/+2Uh, you cant do this in C#?
Thats news to me... I just did it earlier in the week.
And by the way... just because you CAN do something doesn't mean you SHOULD. I can only imagine very rare circumstances where this is actually a GOOD idea. - sandrejev, on 10/12/2007, -0/+2he's using global variables, no digg
- augsod, on 10/12/2007, -0/+2officialchiken is right. C#, and any .NET language for that matter, has reflective capabilities far more powerful than that of Python. Anything that you can do in code at compile time can be done at runtime (usually with a good performance boost too) and you can even compile and load assemblies into your program from code dynamically (although you cannot unload an assembly if it is in the same appdomain as the main program).
- eqbridges, on 10/12/2007, -0/+2absolutely bogus.
check out http://jakarta.apache.org/bcel/ - keithgabryelski, on 10/12/2007, -0/+1The article is nice introduction to class manipulation in PHP, but the author didn't do his homework.
C# provides class manipulation through reflection AND it is type safe -- this provides benefits
PHP can not.
Yes, PHP provides other benefits that C# doesn't -- choose as you will. I actually like the syntax
foreach (someArray as key => value) { ... }
but C# is still my favorite. - officialchicken, on 10/12/2007, -0/+1"Do that in C#"
Example, from the horse's mouth, with examples in 3 languages
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemreflectionemitmethodbuilderclasstopic.asp - jmcmunn, on 10/12/2007, -0/+1
Come on, this is front page news? It's not even true. You can do this with any of the new .Net languages (or probably with other managed languages). But seriously, stop digging this crap. At least research something before you open your mouth. - egbert, on 10/12/2007, -0/+1Nothing new. Lisp, Python, Ruby, ... can all do this.
- ravuya, on 10/12/2007, -1/+2But you *can* do it with lisp or python. And there are lots of things that lisp can do that PHP still won't.
It's a well written article, but I'd be surprised if I'd ever see a PHP jockey using this kind of stuff. - reikiman, on 10/12/2007, -0/+1I blogged my response here: http://weblogs.java.net/blog/robogeek/archive/2006/02/bendy_classes_a.html
I made two points:
a) Java with Annotations offers a fourth solution the guy didn't even present as a possibility.
b) Compile time checking makes it easier to catch bugs due to code mismatches. By dynamically generating object interfaces you push catching programming errors to runtime, which means more bugs will slip through your testing and show up in the field.
- eridius, on 10/12/2007, -0/+1You can do it with ruby too. I basically skimmed the article, but going by the Digg description you can even do this with a compiled language like, say, Objective-C. Well, you can add new methods at least. Adding new ivars could technically be done but would kinda screw with subclasses and it's a wee bit difficult to access said dynamic ivars. But you could mimic it with a single NSDictionary ivar, and you can certainly add dynamic methods or even handle unknown methods.
- oepapel, on 10/12/2007, -1/+2"This is a lie."
I completely agree. It is absolutely possible for ANY managed language to dynamically disassemble, reassemble, generate or otherwise create new or modified objects on the fly. And since the compiler is part of the framework, you can compile those new classes so there is no interpreter penalty.
Actually, a giant advantage that managed languages have over PHP is the concept of interfaces which negates the need to massage the objects in the first place. - officialchicken, on 10/12/2007, -0/+1"Just remember the point of Java/C#/C++ is to NOT do these things :) "
Acutally, C# was designed to do these things from the beginning since it did not support anonymous methods in 1.0. Java added similar metadata functionality at a later date. - FuzzyGuru, on 10/12/2007, -0/+1No Digg
Not only can C# do it, but so can any .NET language as it is part of the framework.
PHP code is usually very ugly.. but not as ugly as most .ASP (vbscript) pages - solarpowered, on 10/12/2007, -0/+1"You can't do that with the Java, C++, or C# languages"
You can with Smalltalk, since the early 80s.
Wow, the more things change, the more they stay the same. - KayMan2k, on 10/12/2007, -0/+1C# / .Net is perfectly capable of doing these 'tricks' (aka run-time class creation). But why do you even need the overhead of a dynamically created class when a "normal" class with a parameters array would work just the same? Heck, .Net offers so many code generation tools that you could just describe your data and not write a single line of code.
- Swel, on 10/12/2007, -0/+1Think ahead, maintenance of software with this kind of hackjob is a nightmare.
The compiler is your best friend. You want it to catch as many of your inevitable errors as possible. That is why type safety, generics, and other OO language features are FEATURES. - oepapel, on 10/12/2007, -0/+1"Compile-time checking only makes sure that your code is type-safe. "
It does more than that. It catches entire categories of common programming errors. Type a name wrong? Caught it. Passed the wrong parameter type or not enough parameters or parameters in the wrong order? Caught it. Missed a class reference? Caught it.
That's partly why programmers use type-safe languages in the first place. - officialchicken, on 10/12/2007, -0/+1"C# / .Net is perfectly capable of doing these 'tricks' (aka run-time class creation). But why do you even need the overhead of a dynamically created class when a "normal" class with a parameters array would work just the same?"
Sometimes applications have to take into account that they may be consuming another API or datasource which will or can change on the fly. Database object mappers come to mind, and creating an 'engine' for your own interpreted scripting language is another case where trying to hardcode a class or method for every possible permutation is downright ignorant. - ThinkFr33ly, on 10/12/2007, -0/+1Wow... considering C# can do every single thing mentioned in that article - NO DIGG!
- digx, on 10/12/2007, -0/+1You can absolutely do this in C#...
- SirNuke, on 10/12/2007, -0/+1When exactly would you use Java, C++, or C# in place of PHP?
- nocotigo, on 10/12/2007, -0/+1I hate when people invoke the words "robust and scalable," and somehow think that just by saying them, they've made an argument.
- ElectricGrandpa, on 10/12/2007, -0/+1"Add designers who think knowing Actionscript makes them developers to the mix and you see the problem. These people are amateurs with no real understanding of the inner workings of computers or the true art of development."
So you want being a developer/programmer to become a closed field, where you can't do it unless you've been doing it your whole life? It doesn't make any sense. You're way too jaded by your own superiority. I'm a professional actionscript developer, and while I don't have a deep knowledge of the "inner workings of computers" or the "true art of development", I do make some damn good stuff that works well and makes my employers happy. I do innovate and problem solve and come up with interesting solutions every day. I may not be involved in the lifelong zen of programming, but I enjoy it. - macenthe, on 10/12/2007, -0/+0"I'm a "PHP Jockey" not because I believe it's the best scripting language, but because it has been the cheapest to implement for the longest amount of time, and it has a huge developer community. The server cost to the client is NIL, which is not the cast for .NET, ColdFusion, or JSP. For small to medium sized businesses PHP is perfect. Sure, Enterprises *might* want something more, but it's good enough for Yahoo! And yes, us jockeys do occasionally whip out the big dynamic object/method schlong."
Amen to this. I work in a university environment creating small scale DBs for departments with at most a dozen staff. I do not need nor want an enterprise scale database that will be expensive to buy/maintain when I can have PHP/MySQL running for NOTHING, neither of which requires enterprise licensing. Even MSSQL/ASP on a simple Win2k3 Server is still nearly $1000 not counting hardware. If PHP were really as awful as people are claiming then I don't think it would be as popular as it is. - headzoo, on 10/12/2007, -0/+0"There's nothing that bores me quicker than a religious holy war over programming languages. Folks tend to overstate the benefits of their favorite language while exaggerating the shortcomings of every other language. I think I'll go read another article."
Amen. Too many people here saying, "Oh, C++ is so much more powerful than PHP!" Who cares... why use a sledge hammer when all you need is a fly swatter. Different languages work well for their intended purpose. There's no such thing as "This language is better than that one". It's a matter of which language is best suited for the task.
On another note, some odd things the author did:
1. Used '=&' to pass an object by reference. No longer needed in PHP 5.x.
2. Used 'global $db'. WTF? Kinda defeats the purpose of OOP.
3. Used preg_match when something much simpler could have been used.
4. Used " " when ' ' would have been a better choice.
And I'm sure there are other things. - richiejp, on 10/12/2007, -0/+0I can't stand PHP, but thats besides the point.
You can create an object model in C that alows for just about any kind of OOP method you want, but most of the time it's alot easier or cleaner to use a language that was designed for it. Personally I go for the simplest solution possible which is normally just a few data structures. - oepapel, on 10/12/2007, -0/+0"Let's get this straight: programming langauges, especially web-based varieties(AS, PHP) do NOT require you to have any working knowledge of a computer. To say you need to be know all about the inner working of a computer in order to program is simply NOT TRUE. I *can* fix my computer if it screws up, but that has NOTHING to do with my ability to code. "
You are just reinforcing the distinction that I was trying to make. Yes, someone who writes scripts can call themselves a programmer and can even be satisfactory in that role. A software developer's job goes beyond the coding and, by knowing how and why their computer works the way it does, can exploit and implement an elegant solution (which may or may not include scripting).
In my company, we have a strategy where all of our technology is purposefully exposed and available to scripting languages. This was a conscious decision so that our customers could customize their installation. There's nothing like a scripting language for customization. But it would have been crazy to try to implement MOST of our functionality in a scripting language. Even C# was a stretch, given the overhead of the VM.
The point I'm trying to make is that this isn't as simple as a language holy war. There is a time and a place for everything and it takes a good programmer to determine it. A bad or even satisfactory programmer will use whatever they happen to know. - GatePig, on 10/12/2007, -0/+0I like PHP for building dynamic web pages.
However, I think morphing classes makes for an architecture that is difficult to maintain. The primary objective of OOP is encapsulation. It makes for easier program maintenance. There are ways to accomplish this although more code is required in any language including PHP.
If terseness is your primary objective (e.g., you are counting the dollars per character typed while programming), then I recommend Perl. - slack0re, on 10/12/2007, -0/+0glad to see not that there are some good articles still being dugg
was worried about this place
all in all the article is ok, all this javascript php ***** isn't that complex though
spend a month in it and you don't need these tutorials
good starting point - slartibartphast, on 10/12/2007, -0/+0I hate to see the "true developer" vs armchair come up, usually most people are both having evolved!
These kinds of things are interesting tricks (yea that all the langs can do), and as you get more experienced, they turn from thinking they are cool to shudders! I'd hate to see this technique in certain kinds of code, look at how viral it is and the security issues.
Self modifying code was a pretty common thing "way back" in the c/assembler days for performance boosting (conditionals costs cpus, just hardcode things and modify that code!) - oepapel, on 10/12/2007, -0/+0"Just curious. Those of you who say this can be done in C#, how exactly is that? Are you talking about reflection? I haven't looked into it in any detail, but I was under the impression that reflection was a way to inspect classes, not to alter them. Or are you talking about extension methods (due in C# 3.0)?"
Look at the System.Reflection.Emit namespace.
Quote From MS: "The System.Reflection.Emit namespace contains classes that allow a compiler or tool to emit metadata and Microsoft intermediate language (MSIL) and optionally generate a PE file on disk. The primary clients of these classes are script engines and compilers."
In other words, you could WRITE a PHP interpreter in C#. - ElectricGrandpa, on 10/12/2007, -0/+0"That's great. The fact that you admit to not having a knowledge of the inner workings of computers is what keeps you from being a developer. At least a good one. Now, don't get me wrong. It's not the script thing. I know plenty of "armchair" programmers or "weekend" programmers that can muddle through their jobs and get satisfactory evaluations. But they are also the first ones to come to me when their development computer breaks down or is acting wonky. It truly is sad when a programmer can't maintain their own system. It's like a professional mechanic that gets a gas attendant to check his oil."
Let's get this straight: programming langauges, especially web-based varieties(AS, PHP) do NOT require you to have any working knowledge of a computer. To say you need to be know all about the inner working of a computer in order to program is simply NOT TRUE. I *can* fix my computer if it screws up, but that has NOTHING to do with my ability to code. - Rickard, on 10/12/2007, -0/+0Just curious. Those of you who say this can be done in C#, how exactly is that? Are you talking about reflection? I haven't looked into it in any detail, but I was under the impression that reflection was a way to inspect classes, not to alter them. Or are you talking about extension methods (due in C# 3.0)?
- Rickard, on 10/12/2007, -0/+0The real WTF is that he uses preg_match() in the __call() method. Now there's a bad idea. Let's fire up the regex engine every time we call a method on our objects. A simple strpos() would do the job a lot more efficiently.
- oepapel, on 10/12/2007, -0/+0"In other words, you could WRITE a PHP interpreter in C#."
And somebody did! The project is called IronPHP and runs wherever mono:: runs. Technically, it's a compiler, not an interpreter.
ironphp.sourceforge.net - Agekay, on 10/12/2007, -0/+0You can do this with Javascript.
- PradaPete, on 10/12/2007, -0/+0Why wouldn't Java, C#, or any newer programming languages not be able to do that? Please elaborate...
- drawkbox, on 10/12/2007, -0/+0PHP is a web only technology (unless you are modding the engine), then C#, Java, C++, C are all better because its a wider platform or market, to devices, web, desktop, spanning desktops. PHP is just a web scripting server page and you are locked there. Usually Java, C# or other soutions are extending enterprise to the web with many different subsets including desktop apps, services, web services, exchanges, etc etc. Java and C#/VB.NET have been corporatized which means they are currenty (for the most part) running the show. PHP is fun and very capable but yes its similar to the attitude that visual basic gets from C developers.
- inactive, on 10/12/2007, -0/+0I'm not so sure PHP is supposed to be compared to Java/C#/C++. Only in slim circumstances at best.
- cockbadger, on 10/12/2007, -0/+0*laugh*
So what exactly does the submitter think php is written in? Magic Cookie Language? Of course not, it's written in a language with even less features than those named above (ANSI C). - gator99, on 10/12/2007, -0/+0If you can't dazzle them with brilliance, baffle them with bs. Objects can become verbose and require that you write a lot of redundant code", is laughable. If you don't know how to write objects this may be true. As far as the dynamic _call, _get and _set, I'm sure its useful, but it's nothing we haven't already done by simply adding another parameter to a "dynamic" function to tell it what to do.
- anztac, on 10/12/2007, -0/+0:: cough :: RUBY
Oh yeah, and Ruby's syntax doesn't suck a goat nut - Rickard, on 10/12/2007, -0/+0"Can you tell what language I developed this site with? How?
http://ourdoings.com/"
Beautiful Report Language. By inputting an invalid e-mail address in the register form and getting a nice fat exception. - smokebomb, on 10/12/2007, -0/+0Yeah the writer unfortunately doesn't have his facts straight. Any language (interpreted or compiled) with a reasonably advanced reflection and a notion of dynamic dispatch tends to have features like this. Still, I had no idea PHP could do this and I'm definetly going to be adding this into my DB wrapper. Better than having to futz around adding and removing accessors everytime I change something in the schema.
-
Show 51 - 94 of 94 discussions



What is Digg?