Skip to content

Instantly share code, notes, and snippets.

@Raynes Raynes/gist:207715
Created Oct 11, 2009

Embed
What would you like to do?
[08:44] <pH_> guys
[08:45] <pH_> how to set an infinite loop in ruby?
[08:47] <wallerdev> loop { }
[08:58] <apeiros_> while 0 ... end # just for the fun of confusing C guys
[09:01] <dominikh> haha
[09:34] <Guest11530> hello
[09:35] <Guest11530> how is a lang like ruby diff from c++
[09:35] <Guest11530> i want to know from the interpreted/compiled perspective
[09:36] <CoolNik123> anyone
[09:36] <wallerdev> sure
[09:36] <wallerdev> i spend most of my time in c++ lately so i can give you a good opinion
[09:37] <wallerdev> c++ is much faster, so it's great for high performance things, the only problem with it you write about 8x more code
[09:37] <wallerdev> and you spend at least 4x longer just debugging things that shouldnt even be issues, like unallocated memory etc
[09:38] <wallerdev> also compiling sucks and takes too long in c++
[09:38] <wallerdev> eventually you get to a point where you just write ruby scripts to generate your c++ code for you
[09:39] <CoolNik123> yes I got u wallerdev - but I am wondering like this ...most codes have to be translated to machine instructions ... so eventually dont both programs have to be made to machine language
[09:39] <wallerdev> yes
[09:39] <CoolNik123> so ruby generates c++ codes ?
[09:39] <wallerdev> but c++ is made into machine code when it compiles
[09:39] <CoolNik123> yeah it is
[09:39] <wallerdev> c++ and ruby both compile to ASM, which is run by the cpu
[09:39] <wallerdev> (in the end)
[09:39] <CoolNik123> so isnt both then compiled ? :)
[09:40] <wallerdev> yes but ruby is "compiled" at runtime
[09:40] <CoolNik123> i think in ruby , program compiler builts something like c++ code ( which is 8x more)
[09:40] <CoolNik123> in essense , it takes out a lot of job from the programmer ...like declration and stuff
[09:41] <wallerdev> yes ruby makes things easier for the programmer
[09:41] <wallerdev> that's one of its goals
[09:41] <wallerdev> c++ does not have that goal haha
[09:41] <CoolNik123> cool , and in the case of PHP
[09:41] <CoolNik123> lol
[09:43] <CoolNik123> is php anyway comparable to ruby
[09:43] <wallerdev> they have some similarities
[09:43] <CoolNik123> though I know both PHP and ROR are almost same type of thingy
[09:43] <CoolNik123> interesting
[09:43] <wallerdev> php is dynamic like ruby
[09:43] <wallerdev> although i don't think it makes it as easy
[09:44] <wallerdev> php doesnt focus as much on object oriented programming, but its possible to do in php
[09:44] <Raynes> The Ruby interpreter is a C++ program that interprets Ruby code in order to run it. Don't make the mistake of thinking that Ruby is 'compiled' in the traditional sense.
[09:44] <wallerdev> Raynes: hm?
[09:44] <CoolNik123> I see , thats very interesitng
[09:44] <Raynes> I was making sure that he knows that Ruby is /not/ a compiled language.
[09:45] <CoolNik123> is perl , python too dependendent on C++
[09:45] <wallerdev> =S
[09:45] <Raynes> At least, I think the interpreter is C++, it might just be C.
[09:45] <CoolNik123> I think that makes a lot of sense to me
[09:45] <wallerdev> pretty sure its just C, and there's many interpereters now
[09:45] <wallerdev> jruby, ironruby etc
[09:46] <CoolNik123> this is very enlightening
[09:46] <CoolNik123> cool - and how about perl / python
[09:46] <wallerdev> python and perl are both similar to ruby
[09:46] <CoolNik123> so run a ruby program , c compiler is probably necessary
[09:46] <CoolNik123> to run
[09:47] <wallerdev> you could use jruby and use a java compiler
[09:47] <CoolNik123> i see
[09:47] <wallerdev> or ironruby and use a .NET compiler
[09:47] <CoolNik123> right ...using the same ruby code
[09:47] <wallerdev> yup
[09:48] <wallerdev> if you used something like jruby though you could call java code from your ruby code
[09:48] <Raynes> You don't need a C compiler unless you intend to build the Ruby interpreter. Note that I'm talking about the primary Ruby interpreter, not the other 10 million interpreters floating around.
[09:48] <CoolNik123> I see
[09:48] <CoolNik123> okay
[09:48] <CoolNik123> ruby interpreter builds a c code isnt that so ?
[09:48] <CoolNik123> and this c code has to be run , which calls in for a c compieler isnt that right
[09:49] <CoolNik123> i thought ruby interpreter is like a superset of ruby programs written in c ...so it generates c code fromt the ruby stuff that write
[09:49] <Horofox> hi guys good day :)
[09:49] <Raynes> The Ruby interpreter isn't a converter. It doesn't convert your program to C, it simply interprets that code.
[09:49] <apeiros> an interpreter doesn't actually compile, no
[09:49] <apeiros> the interpreter itself is compiled and then executes instructions
[09:50] <apeiros> much like e.g. your word processor executes instructions when you type
[09:50] <CoolNik123> interprets and converts to ?
[09:50] <apeiros> it doesn't convert
[09:50] <apeiros> it only executes
[09:50] <Raynes> CoolNik123: It does NOT convert to anything.
[09:50] <CoolNik123> i see
[09:50] <CoolNik123> interpreter can execute ?
[09:50] <Raynes> It just interprets the code and executes the instructions.
[09:50] <CoolNik123> so then isnt compiler the same
[09:51] <Horofox> CoolNik123: imagine a program that when you type
[09:51] <CoolNik123> okay
[09:51] <Horofox> if ( 1 == 1 ) ( say "1 is equal 1";)
[09:51] <Raynes> A compiler takes code and turns that code into some sort of machine language.
[09:51] <CoolNik123> say I write a few things in ruby - it has to be converted to machine language eventually
[09:51] <Horofox> it reads what you typed
[09:51] <apeiros> some interpreters will compile to an intermediary format (bytecode e.g.)
[09:51] <Horofox> then say "1 is equal 1"
[09:51] <Horofox> :P
[09:51] <apeiros> some interpreters might even do complete compilation at one point in time
[09:52] <Horofox> jvm compile some code that is really used to bytecode
[09:52] <CoolNik123> i think i get what u mean Horofox
[09:53] <CoolNik123> interpreter is a like a daemon which accepts ur input and does processing
[09:53] <Horofox> yea like this
[09:53] <Horofox> but still isnt a daemon i think
[09:53] <apeiros> s/daemon/application/
[09:54] <CoolNik123> in c during compilation the machine code is generated for the full program ....
[09:54] <Horofox> yes
[09:54] <CoolNik123> in ruby , the interpreter program is called for every line that u type ...
[09:55] <CoolNik123> I get some idea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.