Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 395 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python vs. Ruby for metaprogramming

#1
I'm currently primarily a [D][1] programmer and am looking to add another language to my toolbox, preferably one that supports the metaprogramming hacks that just can't be done in a statically compiled language like D.

I've read up on Lisp a little and I would love to find a language that allows some of the cool stuff that Lisp does, but without the strange syntax, etc. of Lisp. I don't want to start a language flame war, and I'm sure both Ruby and Python have their tradeoffs, so I'll list what's important to me personally. Please tell me whether Ruby, Python, or some other language would be best for me.

Important:

1. Good metaprogramming. Ability to create classes, methods, functions, etc. at runtime. Preferably, minimal distinction between code and data, Lisp style.
2. Nice, clean, sane syntax and consistent, intuitive semantics. Basically a well thought-out, fun to use, modern language.
3. Multiple paradigms. No one paradigm is right for every project, or even every small subproblem within a project.
4. An interesting language that actually affects the way one thinks about programming.

Somewhat important:

1. Performance. It would be nice if performance was decent, but when performance is a real priority, I'll use D instead.
2. Well-documented.

Not important:

1. Community size, library availability, etc. None of these are characteristics of the language itself, and all can change very quickly.
2. Job availability. I am not a full-time, professional programmer. I am a grad student and programming is tangentially relevant to my research.
3. Any features that are primarily designed with very large projects worked on by a million code monkeys in mind.

[1]:

[To see links please register here]


Reply

#2
I've use Python a very bit, but much more Ruby. However I'd argue they both provide what you asked for.

If I see all your four points then you may at least check:

[To see links please register here]


And Mozart/Oz may be interesting for you also:

[To see links please register here]


Regards
Friedrich
Reply

#3
> I've read up on Lisp a little and I would love to find a language that allows some of the cool stuff that Lisp does, but without the strange syntax, etc. of Lisp.

Wouldn't we all.

> minimal distinction between code and data, Lisp style

Sadly, the minimal distinction between code and data and "strange" syntax are consequences of each other.

If you want easy-to-read syntax, you have Python. However, the code is *not* represented in any of the commonly-used built-in data structures. It fails—as most languages do—in item #1 of your 'important' list. That makes it difficult to provide useful help.

You can't have it all. Remember, you aren't the first to have this thought. If something like your ideal language existed, we'd all be using it. Since the real world falls short of your ideals, you'll have to re-prioritize your wish list. The "important" section has to be rearranged to identify what's *really* important to you.
Reply

#4
Do not to mix Ruby Programming Language with Ruby Implementations, thinking that POSIX threads are not possible in ruby.

You can simply compile with pthread support, and [this was already possible at the time this thread was created][1], if you pardon the pun.

The answer to this question is simple. If you like lisp, you will probably prefer ruby. Or, whatever you like.

[1]:

[To see links please register here]

Reply

#5
My answer would be neither. I know both languages, took a class on Ruby and been programming in python for several years. Lisp is good at metaprogramming due to the fact that its sole purpose is to transform lists, its own source code is just a list of tokens so metaprogramming is natural. The three languages I like best for this type of thing is Rebol, Forth and Factor. Rebol is a very strong dialecting language which takes code from its input stream, runs an expression against it and transforms it using rules written in the language. Very expressive and extremely good at dialecting. Factor and Forth are more or less completely divorced from syntax and you program them by defining and calling words. They are generally mostly written in their own language. You don't write applications in traditional sense, you extend the language by writing your own words to define your particular application. Factor can be especially nice as it has many features I have only seen in smalltalk for evaluating and working with source code. A really nice workspace, interactive documents, etc.
Reply

#6
I would recommend you go with Ruby.

When I first started to learn it, I found it really easy to pick up.
Reply

#7
I recommend Haskell. It isn't much of a contender for "important" criteria 1 (unless you include Template Haskell) or 3 (Haskell is a firmly Functional language, though you'd be surprised how easy it actually is to code imperatively in Haskell if you want to). You'll certainly enjoy Haskell's first class functions, though.

Haskell is a rock solid choice for "important" criterion 2 and 4. Especially #4: "An interesting language that actually affects the way one thinks about programming." Anyone who has learned a significant amount of Haskell can attest to its ability to expand your mind.
Reply

#8
@Jason I respectively disagree. There are differences that make Ruby superior to Python for metaprogramming - both philosophical and pragmatic. For starters, [Ruby gets inheritance right with Single Inheritance and Mixins][1]. And when it comes to metaprogramming you simply need to understand that it's all about the *self*. The canonical difference here is that in Ruby you have access to the *self* object at runtime - in Python you do not!

Unlike Python, in Ruby there is no separate compile or runtime phase. In Ruby, every line of code is executed against a particular *self* object. In Ruby every class inherits from both object and a hidden metaclass. This makes for some interesting dynamics:

class Ninja
def rank
puts "Orange Clan"
end

self.name #=> "Ninja"
end

Using *self.name* accesses the Ninja classes' metaclass *name* method to return the class name of Ninja. Does metaprogramming flower so beautiful in Python? I sincerely doubt it!


[1]:

[To see links please register here]

Reply

#9
Did you try Rebol?
Reply

#10
Honestly, as far as metaprogramming facilities go, Ruby and Python are a lot more similar than some of their adherent like to admit. This review of both language offers a pretty good comparison/review:

*

[To see links please register here]


So, just pick one based on some criteria. Maybe you like Rails and want to study that code. Maybe SciPy is your thing. Look at the ecosystem of libraries, community, etc, and pick one. You certainly won't lose out on some metaprogramming nirvana based on your choice of either.

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through