Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Another one of those things you never have to worry about if you use a statically typed language.


That's actually not true. For instance, the game Alpha Centauri generated custom dynamic functions in RAM at runtime to draw user created units.


This is a great way of disagreeing with a position. Polite and backed by a concise fact. Thanks.


How do you know that? I'm not saying you're wrong, I'm just curious. Did you work on the game? Are you a hardcore modder?


"When I first came onboard with Loki, the Alpha Centauri Plantary Pack was my first porting project. I didn't know what to expect from commercial game code, but I sure wasn't expecting what I found in the SMAC codebase. Tens of thousands of lines of assembly code was in SMAC, some of which was self-modifying. I spent most of my time looking at memory in the debugger and flipping bits."


This has nothing to do with static vs dynamic typing. In Java, for example, you can easily invoke a method named by a string that's not defined at compile time (using the reflection api).


But since you can't define methods using reflection, I'd say this isn't used much and isn't really a problem in Java. Are you really having trouble decyphering a Java function relying on home-made dynamic dispatch?

But yeah, I'd say it's more about http://en.wikipedia.org/wiki/Dynamic_dispatch than static/dynamic typing. You can have dynamic dispatch in a statically typed language. I don't know how OP would feel about virtual methods in C++ since he resists using an IDE.


> But since you can't define methods using reflection, I'd say this isn't used much and isn't really a problem in Java.

You can do about anything you want with cglib / Javassist. Dynamically subtyping or byte code re-writing a class is how many Java ORMs work.


Correct. You can also use Dynamic Proxies, for metaprogramming, which are built right into the language.


That's a dynamically typed sub-language within Java.


Counterpoint: Macros. Though you could preprocess the code and grep that, it wouldn't work too well. Eclipse-et-al can give you a sort-of-works-most-of-the-time navigation features that work with the preprocessed code, which can overcome the macro problem, mostly.


Macros still can cause a lot of problems. See some of the crazy C++ macros or Template Haskell.


Statically typed languages also have worrisome features.

  #define readinto(obj, fd) (isatty(fd) ? readbuffered(obj, fd, findttystate()) : readfromfile(obj, fd))


In a statically typed language you have to worry about many other things tough =)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: