To be 100% honest I've never heard that said about javascript. Probably because javascript doesn't have real objects. Javascript is a functional language that uses prototypes to give the appearance of objects. In the next version of the language there will be classes but it is still at its heart a functional language.
Ruby on the other hand everything is an object. On anything in Ruby you can ask it what class it is and what it inherits from. Everything comes from a class and has methods.
Personally I find that JavaScript having OO envy is what leads to a lot of the badly written JavaScript i s
To be 100% honest I've never heard that said about javascript. Probably because javascript doesn't have real objects. Javascript is a functional language that uses prototypes to give the appearance of objects. In the next version of the language there will be classes but it is still at its heart a functional language.
Ruby on the other hand everything is an object. On anything in Ruby you can ask it what class it is and what it inherits from. Everything comes from a class and has methods.
Personally I find that JavaScript having OO envy is what leads to a lot of the badly written JavaScript i see. JavaScript written in a functional style can really be nice to work with, easy to understand and really fast.
Where do I start?
I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.
Here are the biggest mistakes people are making and how to fix them:
Not having a separate high interest savings account
Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.
Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.
Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of th
Where do I start?
I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.
Here are the biggest mistakes people are making and how to fix them:
Not having a separate high interest savings account
Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.
Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.
Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of the biggest mistakes and easiest ones to fix.
Overpaying on car insurance
You’ve heard it a million times before, but the average American family still overspends by $417/year on car insurance.
If you’ve been with the same insurer for years, chances are you are one of them.
Pull up Coverage.com, a free site that will compare prices for you, answer the questions on the page, and it will show you how much you could be saving.
That’s it. You’ll likely be saving a bunch of money. Here’s a link to give it a try.
Consistently being in debt
If you’ve got $10K+ in debt (credit cards…medical bills…anything really) you could use a debt relief program and potentially reduce by over 20%.
Here’s how to see if you qualify:
Head over to this Debt Relief comparison website here, then simply answer the questions to see if you qualify.
It’s as simple as that. You’ll likely end up paying less than you owed before and you could be debt free in as little as 2 years.
Missing out on free money to invest
It’s no secret that millionaires love investing, but for the rest of us, it can seem out of reach.
Times have changed. There are a number of investing platforms that will give you a bonus to open an account and get started. All you have to do is open the account and invest at least $25, and you could get up to $1000 in bonus.
Pretty sweet deal right? Here is a link to some of the best options.
Having bad credit
A low credit score can come back to bite you in so many ways in the future.
From that next rental application to getting approved for any type of loan or credit card, if you have a bad history with credit, the good news is you can fix it.
Head over to BankRate.com and answer a few questions to see if you qualify. It only takes a few minutes and could save you from a major upset down the line.
How to get started
Hope this helps! Here are the links to get started:
Have a separate savings account
Stop overpaying for car insurance
Finally get out of debt
Start investing with a free bonus
Fix your credit
Your question is mis-stated, based on the quote you're providing.
In Ruby, literally everything is an object in both the literal sense (all things descend from the "Object" superclass) and the practical sense (all things have methods and/or properties that can be accessed with varying levels of access).
The quote you included says, "almost everything is an object" (emphasis mine). The qualifying clarification is in the sentence that follows that statement, and explains the difference in interpretation (the main one being that Ruby does not have primitives).
As an example, you can do this in Rub
Your question is mis-stated, based on the quote you're providing.
In Ruby, literally everything is an object in both the literal sense (all things descend from the "Object" superclass) and the practical sense (all things have methods and/or properties that can be accessed with varying levels of access).
The quote you included says, "almost everything is an object" (emphasis mine). The qualifying clarification is in the sentence that follows that statement, and explains the difference in interpretation (the main one being that Ruby does not have primitives).
As an example, you can do this in Ruby:
> 5.times { puts "Foo"; }
but in Javascript, you'd have to do:
> for (var i = 0; i < 5; i++) { console.log("Foo"); }
In the former, "times" is a method of "5" which is an instance of the Fixnum object. Even though "5" is technically a primitive, it is dereferenced as an object by the interpreter.
Firstly, JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive. Where HTML and CSS are languages that give structure and style to web pages, JavaScript gives web pages interactive elements that engage a user. Common examples of JavaScript that you might use every day include the search box on Amazon, a news recap
Firstly, JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive. Where HTML and CSS are languages that give structure and style to web pages, JavaScript gives web pages interactive elements that engage a user. Common examples of JavaScript that you might use every day include the search box on Amazon, a news recap video embedded in The New York Times, or refreshing your Twitter feed. Incorporating JavaScript improves the user experience of the web page by converting it from a static page into an interactive one. To recap, JavaScript adds behavior to web pages. Developers can use various JavaScript frameworks for developing and building web and mobile apps. JavaScript frameworks are collections of JavaScript code libraries that provide developers with pre-written code to use for routine programming features and tasks literally a framework to build websites or web applications around. Popular JavaScript front-end frameworks include React, React Native, Angular, and Vue. Many companies use Node.js, a JavaScript runtime environment built on Google Chrome’s JavaScript V8 engine. A few famous examples include Paypal, LinkedIn, Netflix, and Uber.
Whereas, Ruby is a scripting language built from the ground up for use in front end and back end web development and similar applications. It is a robust, dynamically typed, object-oriented language with syntax so easy to understand and high-level that it’s considered as close as you can get to coding in English. More than one person has commented that they could basically understand Ruby code even without knowing how to program. Released in the 1990s, Ruby is an open-sourced language created by the Japanese programmer Yukihiro “Matz” Matsumoto. He has stated that the language is designed to be both fun and productive. Ruby is scripted, meaning that it’s an interpreted language rather than a compiled one.
———————————Reason to learn JavaScript——————————————
It’s the most popular programming language: JavaScript is the most popular programming language used by professional developers today. Even back-end developers choose JavaScript more often than not.
It’s in your browser: JavaScript is, without question, the default language of the internet. You need to look no further than your browser for proof since JavaScript was most likely used to develop it. Since browsers are a necessary part of any user’s online experience, it’s easy to see why JavaScript is so significant.
JavaScript also exists outside of the internet: JavaScript has many uses that go beyond its traditional internet roles. It powers smart televisions, works with the internet of things (IoT), creates native apps for iOS and Android, and builds cross-platform desktop apps, to name a few.
JavaScript is Ideal for Newbies: Since it’s already installed on every web browser today, JavaScript spares the rookies from the chore of setting up a development environment. Newcomers can just jump in and start coding. It’s one of the most accessible entries into coding available, a value-add for beginners. There is also a large online community that offers support and advice. Also, JavaScript is an excellent tool for beginning programmers who want to expand their skillset into other languages. JavaScript supports valuable skills such as object-oriented, functional, and imperative styles of programming. Beginner developers, in turn, can apply these skills to any new language they want to learn, like Python, Java, or C++.
JavaScript is Easy to Learn: Not only is it a natural language to use, but JavaScript is also easy to pick up. JavaScript turns intricate details into abstracts, making things easier for the newcomer. Unlike the higher-level languages, JavaScript has more of a natural language feel to it.
You Can Create Visual Effects and Other Eye-catching Aesthetic Features: There’s building a web page, and then there’s building a visually appealing web page that attracts the user’s attention and encourages interaction. JavaScript is so versatile that you can use it to easily add cool design elements such as animation, interactive maps, and scrolling video. Organizations and clients want web designers who can not only put together a technically sound page but one that also will lure visitors. If you know JavaScript, you can deliver.
JavaScript is Versatile: Far from being a one-trick pony, JavaScript empowers a programmer to handle any aspect of app design. Do you want to do user-side (front-end) coding? You can do it in conjunction with Angular. Are you more interested in the server-side (back-end)? Bring Node.js into the mix and you can do that, too. You can also create desktop, mobile, and web apps with Electron, React Native, and React. If you’re intrigued by machine learning, then JavaScript will help you there as well.
JavaScript also Affects Big Data and the Cloud: JavaScript Object Notation (JSON) is the go-to standard for data exchanges on today’s internet. NoSQL databases use JSON documents for record storage; and although JSON plays well with any programming language, it does best with JavaScript. Also, more developers are turning to Node.js to build cloud-based apps, a very much in-demand market.
———————————Reason to learn Ruby——————————————
Ruby on Rails is a web application framework: Ruby on Rails is basically a collection of shortcuts written in Ruby that lets you build web applications basically websites really quickly. The benefit to learning a web application framework (like Ruby on Rails) before learning a programming language itself (like Ruby) is that you’ll make quicker progress in the beginning, you’ll have a real site that you can share with friends, and you’ll see how the things you’re learning actually apply to the things you want to be able to do.
Some of the biggest websites in the world are built with Ruby on Rails: Basecamp, Airbnb, Bleacher Report, Scribd, Groupon, Gumroad, Hulu, Kickstarter, Pitchfork, Sendgrid, Soundcloud, Square, Yammer, Crunchbase, Slideshare, Funny or Die, Zendesk, Github, Shopify. As you can see, we were not kidding when we said the biggest web...
I would not guide with that phrase. It does not say much.
It's like saying: in this world everything is an atom. Or in this world everything is an electron.
All it expresses is that you can see both languages as if they were composed by objects. And what is an object? is what composes these languages.
Note the circular reference.
Object has a lot of meanings which are valid according the context. Here is a good one Object (computer science).
If you want to write better essays, it’s helpful to understand the criteria teachers use to score them. Instead of solely focusing on the grade you are given, focus on how you are being graded and how you can improve, even if you are already getting a high grade.
Development of Your Thesis
A thesis is the essence of your paper—the claim you are making, the point you are trying to prove. All the other paragraphs in your essay will revolve around this one central idea. Your thesis statement consists of the one or two sentences of your introduction that explain what your position on the topic at ha
If you want to write better essays, it’s helpful to understand the criteria teachers use to score them. Instead of solely focusing on the grade you are given, focus on how you are being graded and how you can improve, even if you are already getting a high grade.
Development of Your Thesis
A thesis is the essence of your paper—the claim you are making, the point you are trying to prove. All the other paragraphs in your essay will revolve around this one central idea. Your thesis statement consists of the one or two sentences of your introduction that explain what your position on the topic at hand is. Teachers will evaluate all your other paragraphs on how well they relate to or support this statement.
Strong Form
A good essay presents thoughts in a logical order. The format should be easy to follow. The introduction should flow naturally to the body paragraphs, and the conclusion should tie everything together. The best way to do this is to lay out the outline of your paper before you begin. After you finish your essay, review the form to see if thoughts progress naturally. Ensure your paragraphs and sentences are in a logical order, the transitions are smooth so that the paragraphs are coherently connected, and that your body paragraphs relate to the thesis statement.
Style
Just as your clothes express your personality, the style of your essay reveals your writing persona. You demonstrate your fluency by writing precise sentences that vary in form. A mature writer uses various types of sentences, idiomatic phrases, and demonstrates knowledge of genre-specific vocabulary, all the while ensuring the writing reflects your authentic voice.
Conventions
Conventions include spelling, punctuation, sentence structure, and grammar. Having lots of mistakes suggests carelessness and diminishes the credibility of your arguments. Furthermore, because most essays are written on computers these days, there is a lower tolerance for spelling mistakes, which can easily be avoided with spell-checking tools such as Grammarly. Beyond spelling, Grammarly can also help to weed out other major grammatical errors. Follow up with a close reading of your entire paper.
Support and References
Finally, your teacher will examine your resources. Select information from reliable websites, articles, and books. Use quotes and paraphrases to support your ideas, but be sure to credit your sources correctly. Also, always remember that copying five consecutive words or more from any source constitutes plagiarism. If you are concerned about unintentionally quoting your sources, Grammarly Pro offers a plagiarism detector so you can always double-check your work.
The grades you get on your essays are important, but you can never improve your writing if they are the only things you consider. Focus on improving your essays’ overall structure—the thesis development, form, style, conventions, and support. Learning to master these five elements will cause your scores to soar!
I agree with Matthew Johnson.
One can build a robust and sophisticated full-stack web app with Ruby (on Rails or lighter weight Sinatra) with little to no Javascript.
The importance of JavaScript comes later when someone convinces you that they need you to build a Single Page Application.
So I suggest you set up your curriculum in this order:
- Learn Ruby on Rails from soup (html templates, controllers) to nuts (models and ActiveRecord database migrations);
- Learn rudimentary Javascript and JQuery because you'll likely need to add some user-friendly schmutz to your server-side Rails web app;
- Progr
I agree with Matthew Johnson.
One can build a robust and sophisticated full-stack web app with Ruby (on Rails or lighter weight Sinatra) with little to no Javascript.
The importance of JavaScript comes later when someone convinces you that they need you to build a Single Page Application.
So I suggest you set up your curriculum in this order:
- Learn Ruby on Rails from soup (html templates, controllers) to nuts (models and ActiveRecord database migrations);
- Learn rudimentary Javascript and JQuery because you'll likely need to add some user-friendly schmutz to your server-side Rails web app;
- Progress to intermediate Javascript. Look into frameworks like Angular.js and Backbone.js (w/ Marionette). But before you do too much Javascript, check out CoffeeScript.
- Learn CoffeeScript because it's Ruby-like, you will already know Ruby, and CoffeeScript can generate nearly perfect JavaScript with much less WTF head scratching. Ultimately you'll want to be able to write sophisticated client side code, but you'll want to try to avoid the hairball that Javascript invariably grows into with a Single Page Application.
All the best in your journey.
Javascript has some gotchas, you never need to learn "everything about javascript", but surely you need to learn all good parts - and be aware of bad parts. Douglas Crockford's book - JavaScript: The Good Parts: Douglas Crockford: 9780596517748: Amazon.com: Books
Javascript is small and to write code substantial in size and maintainable at the same time, you need to know about Javascript Idioms. This has a very important role when you are writing libraries for others. Although Douglas Crockford's book covers almost a lot of good practices, but you may wish to look at: JavaScript Patterns: Stoy
Javascript has some gotchas, you never need to learn "everything about javascript", but surely you need to learn all good parts - and be aware of bad parts. Douglas Crockford's book - JavaScript: The Good Parts: Douglas Crockford: 9780596517748: Amazon.com: Books
Javascript is small and to write code substantial in size and maintainable at the same time, you need to know about Javascript Idioms. This has a very important role when you are writing libraries for others. Although Douglas Crockford's book covers almost a lot of good practices, but you may wish to look at: JavaScript Patterns: Stoyan Stefanov: 9780596806750: Amazon.com: Books . Sometimes you need a full reference of Javascript. Look for Amazon.com: JavaScript: The Definitive Guide: Activate Your Web Pages (Definitive Guides) eBook: David Flanagan: Books
Fortunately there is a small and beautiful language named CoffeeScript, which provides a higher level abstraction over javascript, implementing all good parts. See here: CoffeeScript
To learn Javascript, you need to run some programs. You can find one already installed with your browser or you can install something like Firebug in your browser. Recommended is to use node.js
Hope it helps.
I once met a man who drove a modest Toyota Corolla, wore beat-up sneakers, and looked like he’d lived the same way for decades. But what really caught my attention was when he casually mentioned he was retired at 45 with more money than he could ever spend. I couldn’t help but ask, “How did you do it?”
He smiled and said, “The secret to saving money is knowing where to look for the waste—and car insurance is one of the easiest places to start.”
He then walked me through a few strategies that I’d never thought of before. Here’s what I learned:
1. Make insurance companies fight for your business
Mos
I once met a man who drove a modest Toyota Corolla, wore beat-up sneakers, and looked like he’d lived the same way for decades. But what really caught my attention was when he casually mentioned he was retired at 45 with more money than he could ever spend. I couldn’t help but ask, “How did you do it?”
He smiled and said, “The secret to saving money is knowing where to look for the waste—and car insurance is one of the easiest places to start.”
He then walked me through a few strategies that I’d never thought of before. Here’s what I learned:
1. Make insurance companies fight for your business
Most people just stick with the same insurer year after year, but that’s what the companies are counting on. This guy used tools like Coverage.com to compare rates every time his policy came up for renewal. It only took him a few minutes, and he said he’d saved hundreds each year by letting insurers compete for his business.
Click here to try Coverage.com and see how much you could save today.
2. Take advantage of safe driver programs
He mentioned that some companies reward good drivers with significant discounts. By signing up for a program that tracked his driving habits for just a month, he qualified for a lower rate. “It’s like a test where you already know the answers,” he joked.
You can find a list of insurance companies offering safe driver discounts here and start saving on your next policy.
3. Bundle your policies
He bundled his auto insurance with his home insurance and saved big. “Most companies will give you a discount if you combine your policies with them. It’s easy money,” he explained. If you haven’t bundled yet, ask your insurer what discounts they offer—or look for new ones that do.
4. Drop coverage you don’t need
He also emphasized reassessing coverage every year. If your car isn’t worth much anymore, it might be time to drop collision or comprehensive coverage. “You shouldn’t be paying more to insure the car than it’s worth,” he said.
5. Look for hidden fees or overpriced add-ons
One of his final tips was to avoid extras like roadside assistance, which can often be purchased elsewhere for less. “It’s those little fees you don’t think about that add up,” he warned.
The Secret? Stop Overpaying
The real “secret” isn’t about cutting corners—it’s about being proactive. Car insurance companies are counting on you to stay complacent, but with tools like Coverage.com and a little effort, you can make sure you’re only paying for what you need—and saving hundreds in the process.
If you’re ready to start saving, take a moment to:
- Compare rates now on Coverage.com
- Check if you qualify for safe driver discounts
- Reevaluate your coverage today
Saving money on auto insurance doesn’t have to be complicated—you just have to know where to look. If you'd like to support my work, feel free to use the links in this post—they help me continue creating valuable content.
It's just a point of view, and not very productive.
An object in JS is a collection of properties and functions. Whether any collection of properties and functions is an object, may be worth a discussion, but it's boring. I would not go with those objects at all if you use JS. Objects are just an illusion, coming from UI programming of about 20-30 years ago.
Your question is not dumb. Relax :-)
There’s nothing special about JavaScript, which is a dynamic scripting language like Ruby, Python, PHP or Lua, just to name a few. For many years it was one of the most despised languages in the world, and just as slow (or more) than Ruby.
It’s just that for political reasons, it became the only language supported natively by all the major browsers, so whether you liked it or not, you had to learn it if you were into web development.
Its situation changed dramatically when Google created the V8 JavaScript engine. They hired Lars bak, the creator of the Java Ho
Your question is not dumb. Relax :-)
There’s nothing special about JavaScript, which is a dynamic scripting language like Ruby, Python, PHP or Lua, just to name a few. For many years it was one of the most despised languages in the world, and just as slow (or more) than Ruby.
It’s just that for political reasons, it became the only language supported natively by all the major browsers, so whether you liked it or not, you had to learn it if you were into web development.
Its situation changed dramatically when Google created the V8 JavaScript engine. They hired Lars bak, the creator of the Java HotSpot VM, which is a state of the art virtual machine for the Java language. With V8, the speed and performance of Javascript increased dramatically, approaching in some cases those of statically compiled languages. But there is a lot of investment, talent and man hours behind V8, and it’s not something easily replicated by open source contributors for other languages.
Anyway, there are some rather successful projects out there that employ similar techniques. For example PYPY, which is a just in time python engine, which runs up to 7.5 times faster than regular Python. Unfortuntely, it doesn’t support C extensions very well, and that’s the reason it didn’t replace regular Python so far.
Another successful project, that’s older than V*, is LuaJit, a just-in-time engine for Lua. It’s very, very fast. But Lua is a much simpler language than the others, so it’s easier to speed up. Although that doesn’t diminish a bit the talent of its creator, Mike Pall.
So in theory, and provided there’s the talent, time, money and commitment to do it, Ruby could be as fast as JavaScript.
GOOD NEWS:
There’s already a language that borrows much of Ruby’s features and syntax, and that runs at Javascript’s speed: CoffeeScript. Coffeescript is actually an alternative syntax for Javascript. It’s a transpiler (a trans-compiler) that translates Coffee’s code to plain old Javascript so, in the end, it runs as fast as its compilation target language. Check it out.
In both languages it basically means the same.
- Number.prototype.sayHello = function () {
- return "Hello! I'm " + this.valueOf();
- };
- 42..sayHello(); // returns "Hello! I'm 42"
- String.prototype.sayHello = Number.prototype.sayHello;
- "a string".sayHello(); // returns "Hello! I'm a string"
In Ruby you would have been able to write 42.sayHello
(after the equivalent Monkey patch), but here the only difference is you need two dots to disambiguate from a float literal (thanks to Quora User for this one).
This is useful for example for attaching meaningful constants to your functions, because functions are
In both languages it basically means the same.
- Number.prototype.sayHello = function () {
- return "Hello! I'm " + this.valueOf();
- };
- 42..sayHello(); // returns "Hello! I'm 42"
- String.prototype.sayHello = Number.prototype.sayHello;
- "a string".sayHello(); // returns "Hello! I'm a string"
In Ruby you would have been able to write 42.sayHello
(after the equivalent Monkey patch), but here the only difference is you need two dots to disambiguate from a float literal (thanks to Quora User for this one).
This is useful for example for attaching meaningful constants to your functions, because functions are objects, too:
- function Shape(shapeType) {
- if (shapeType === Shape.TYPE.SQUARE) {
- this.w = this.h = this.x = this.y = 0;
- }
- else {
- throw new Error("Unsupported shape requested");
- }
- }
- Shape.TYPE = { SQUARE: 1, CIRCLE: 2 };
- new Shape(Shape.TYPE.SQUARE);
- // returns Shape instance "Object { y: 0, x: 0, h: 0, w: 0 }"
- new Shape(Shape.TYPE.CIRCLE);
- // throws "Error: Unsupported shape requested"
Everything in PHP is awful.
HTML - Hypertext Markup Language.
CSS - Cascading Stylesheet.
JS - JavaScript.
RoR - Ruby on Rails.
HTML is like blueprints: this how you know what will be laid out, how, and in what order.
CSS is the language for styling the HTML elements. It's how you fan make 3 columns with blue backgrounds and centered text.
JS is a client- and server-side programming language. It is how dynamic events take place in the web browser. It is also the language for the increasingly popular server runtime environment called Nodejs, which is what allows for server-side programming in JavaScript.
RoR is a framework for t
HTML - Hypertext Markup Language.
CSS - Cascading Stylesheet.
JS - JavaScript.
RoR - Ruby on Rails.
HTML is like blueprints: this how you know what will be laid out, how, and in what order.
CSS is the language for styling the HTML elements. It's how you fan make 3 columns with blue backgrounds and centered text.
JS is a client- and server-side programming language. It is how dynamic events take place in the web browser. It is also the language for the increasingly popular server runtime environment called Nodejs, which is what allows for server-side programming in JavaScript.
RoR is a framework for the server-side programming language called Ruby.
In most object-oriented languages, there are two distinct entities: classes and instances (a.k.a objects). A class is like a blueprint. It describes how instances should behave. In most cases, that's all the blueprint does.
In real life, you wouldn't (I hope) go to the bathroom in a blueprint of a house. And you wouldn't use classes for actually getting work done. You'd use them to create the obje
In most object-oriented languages, there are two distinct entities: classes and instances (a.k.a objects). A class is like a blueprint. It describes how instances should behave. In most cases, that's all the blueprint does.
In real life, you wouldn't (I hope) go to the bathroom in a blueprint of a house. And you wouldn't use classes for actually getting work done. You'd use them to create the objects that do the work. You wouldn't try to fly a Spaceship class. You'd fly the instances of spaceships you built from it.
(Another metaphor: you wouldn't actually eat a recipe. You'd use a recipe to
create
what you eat. With a single recipe, you could make a thousand loaves of bread. Still, the recipe isn't the same thing as the bread.
You also wouldn't use a loaf of bread as a recipe. If someone asked you how to make bread, you wouldn't hand him a loaf and say, "Reverse-engineer this." You'd just give him the recipe.)
In Javascript, there are no blueprints. There are just objects that relate to one another any way you want them to. If you want, you can make one object a proxy (or delegate) for another.
Lets say your house acts a proxy for mine: a guests visits me and says, "Can I use your bathroom?" I know my toilet is broken, but I say, "Sure. It's across the street." I point to your house. I call your bathroom "mine," because your house is a proxy for my house. (Because you have agreed to let my guests use your bathroom.)
The key point here is that though my house delegates to yours, yours isn't a blueprint for mine. Both of our houses are real houses--real objects.
In most class-based (blueprint-based) languages, you create blueprints somewhat like this:
- class Animal:
- walk() { log('I'm walking') }
- eat() { log('I'm eating') }
- speak() { log('I'm speaking') }
Walk, eat, and speak are things animals can do. However, Animal (with a capital-A) can't walk, eat, or speak, because it's just a blueprint. To make an actual instance of an animal, you do something like this:
- Animal.walk() // => Error*!
- frog = new Animal
- frog.walk() // => I'm walking
- frog.speak(); // => I'm eating
- giraffe = new Animal
- giraffe.walk(); // => I'm walking
- giraffe.eat(); // => I'm eating
You don't need to tell each type of animal how to walk. That code is in the blueprint, and all the instances inherit walking from it. (There are usually ways of overriding the blueprint's behavior, if you want a specific instance to behave differently from most other members of a class.)
In Javascript, you'd do something like this:
- const animal = {
- walk() { console.log('I'm walking');
- eat() { console.log('I'm eating');
- speak() { console.log('I'm speaking');
- }
- You may think of animal as a blueprint, but it's an actual object. There's nothing stopping you from doing this:
- [code]
- animal.walk(); // => I'm walking
But you can also use animal as a proxy for other objects:
- const horse = Object.create(animal);
- const elephant = Object.create(animal);
- //A more accurate name for Object.create
- //might be createNewObjectWithThisProxy(animal);
- horse.walk(); // => I'm walking
- elephant.walk(); // => I'm walking
What's really important to understand is that the walk, eat, and speak functions have
not
been copied into horse and elephant. Rather, animal is acting as a proxy for horse and elephant. JavaScript is saying, "If horse and elephant don't have their own walk, eat, or speak functions, they can use animal's.
We can prove horse and elephant don't have their own copies by changing animal's versions after horse and elephant are created:
- const horse = Object.create(animal);
- const elephant = Object.create(animal);
- horse.walk(); // => I'm walking
- elephant.walk(); // => I'm walking
- animal.walk = function() {
- console.log('I'm too tired to walk');
- }
- horse.walk(); // => I'm too tired to walk
- elephant.walk(); // => I'm too tired to walk
There's no difference in kind between animal and elephant. Both are just JavaScript objects. They happen to have a certain kind of relationship with each other (elephant can borrow animal's functions), but there's no blueprint.
We can give elephant its own walk function, which will block the connection to the proxy:
- const animal = {
- walk() { console.log('I'm walking');
- eat() { console.log('I'm eating');
- speak() { console.log('I'm speaking');
- }
- const horse = Object.create(animal);
- const elephant = Object.create(animal);
- horse.walk(); // => I'm walking
- elephant.walk(); // => I'm walking
- elephant.walk = function() {
- console.log('I'm strutting my stuff!!!');
- }
- animal.walk(); // => I'm walking
- horse.walk(); // => I'm walking
- elephant.walk(); // => I'm strutting my stuff
- animal.eat(); // => I'm eating
- horse.eat(); // => I'm eating
- // Just the walk function is blocked
- elephant.eat(); // => I'm eating
If you call a function on an object--elephant.walk()--JavaScript checks to see if that object has a version of that function. If it does, JavaScript runs it. If it doesn't, JavaScript checks to see if the object has a proxy, and, if it does, checks to see if the proxy has the function.
"Use my bathroom. But if I don't have one, use the bathroom in the house across the street."
Now, you can ignore these details: though you
can
call animal.walk(), you can choose not to, instead only calling walk() on specific animals, like horse and elephant. If you choose to do that, you can think of animal as a blueprint. It's not, but you can kind of imagine it is. You can call animal a class and horse and elephant instances of the class. That's not what's happening under-the-hood (or even over it, really), but, if you want, you can think of it that way.
If I make a house and stop anyone from living in it--and then call it "the blueprint" and use it as a template for other houses--I can pretend like it's somehow not a house, even though it is.
That's what's going on in JavaScript. The language has vocabulary words like "class" which make it seem as if one object is a blueprint for others. This is an illusion. It's syntactic sugar to make the language seem familiar to people coming from more-traditional object-oriented languages.
People debate about the wisdom of this approach:
PRO: Developers coming from Java, PHP, C++, etc will feel instantly at home.
CON: Yes, but they will be m...
You should pick one language and stick with it until you know the basics.
As a learner you will have enough to deal with.
JavaScript and Ruby has different purposes, syntaxes, functions and classes making it complex to learn.
What language is pretty much up to you.
You're not necessarily limited to those two languages since many languages can be used for web development, including Java, Perl, PHP, and Python.
As with Ruby they will need a little preparations; buying hosting or setting up your own web server.
With JavaScript you could start with a text editor and a browser. But even thoug
You should pick one language and stick with it until you know the basics.
As a learner you will have enough to deal with.
JavaScript and Ruby has different purposes, syntaxes, functions and classes making it complex to learn.
What language is pretty much up to you.
You're not necessarily limited to those two languages since many languages can be used for web development, including Java, Perl, PHP, and Python.
As with Ruby they will need a little preparations; buying hosting or setting up your own web server.
With JavaScript you could start with a text editor and a browser. But even though JavaScript is easier to begin with, you will find it limited
to code at the client side. JavaScript can be also used on server side by installing node.js or similar platforms.
Ruby vs Python
Ruby is famous for being a fast way to become productive on the web with the Ruby on Rails framework. But Python has it own frameworks for the web, including Django that many consider as useful.
Do you always need JavaScript?
There are frameworks for the server side language that will do most or all of the things that you need JavaScript for by generating that code for you. One example is Remote Application Platform (RAP), but there are many others. Knowing some JavaScript will however be helpful in edge cases.
EDIT: A lot of what I’ve said here has been fixed by ES6 and the overall JavaScript community. At this rate, I’d say it’s safer to learn JS over Ruby. However for posterity purposes…
No no no. Do not learn JavaScript first. JS is my first love, and my strongest language, but I'll be the first to admit that it has it's questionable pitfalls.
Please trust me on this. Learn Ruby first.
Ruby let's you think about the problem at hand, and not about JS shenanigans.
Ruby has convenience methods, like each and select (libraries like underscore and lo-dash will hook you up with these eventually, but don't
EDIT: A lot of what I’ve said here has been fixed by ES6 and the overall JavaScript community. At this rate, I’d say it’s safer to learn JS over Ruby. However for posterity purposes…
No no no. Do not learn JavaScript first. JS is my first love, and my strongest language, but I'll be the first to admit that it has it's questionable pitfalls.
Please trust me on this. Learn Ruby first.
Ruby let's you think about the problem at hand, and not about JS shenanigans.
Ruby has convenience methods, like each and select (libraries like underscore and lo-dash will hook you up with these eventually, but don't get caught up in that right now), which help you accomplish simple concepts that allow you to focus on the programming problem at hand.
Ruby has a glorious REPL, built into every Mac.
Ruby is the language of the most easily accessible REST framework around, Rails. If you really want to be a full stack dev, starting with Rails is a great idea.
JS might be more modular at this point, as you can realistically write it server and client side these days, but Ruby will make your learning process a ton more fun, guaranteed.
Good luck out there.
The main reason to learn Ruby is if you are working in a context where Ruby is required. It is a comparatively little-known language (fewer than 7% of programmers use it), so if you can find a client who needs it, you’ll be very popular. I myself was once offered a job merely because I was willing to learn Ruby on the job.
Beyond that, here are some other reasons:
- Ruby is fun
- Ruby is powerful
- Ruby has a consistent design
- Ruby is easy to learn
Also, Ruby is often paired with a framework called “Ruby on Rails” that makes it trivially easy to build programs that follow a certain well-known and useful p
The main reason to learn Ruby is if you are working in a context where Ruby is required. It is a comparatively little-known language (fewer than 7% of programmers use it), so if you can find a client who needs it, you’ll be very popular. I myself was once offered a job merely because I was willing to learn Ruby on the job.
Beyond that, here are some other reasons:
- Ruby is fun
- Ruby is powerful
- Ruby has a consistent design
- Ruby is easy to learn
Also, Ruby is often paired with a framework called “Ruby on Rails” that makes it trivially easy to build programs that follow a certain well-known and useful pattern (model-view-controller). Once you learn this, your programs will almost write themselves!
As a beginner, it depends upon your capacity for learning, but overall no, it's not smart to be learning two languages at the same time.
The one thing going for you is that JavaScript and Ruby share some similarities (similar syntax, built-in arrays and maps, both can be object oriented and functional) but that's about it.
I would stick with learning just Ruby first. Then I assume you'll want to learn Rails for developing Web apps.
For JavaScript on the front end, just learn enough to use frameworks such as JQuery and you should be good. If you really want to learn JavaScript to the point where y
As a beginner, it depends upon your capacity for learning, but overall no, it's not smart to be learning two languages at the same time.
The one thing going for you is that JavaScript and Ruby share some similarities (similar syntax, built-in arrays and maps, both can be object oriented and functional) but that's about it.
I would stick with learning just Ruby first. Then I assume you'll want to learn Rails for developing Web apps.
For JavaScript on the front end, just learn enough to use frameworks such as JQuery and you should be good. If you really want to learn JavaScript to the point where you can write your own front-end libraries then you can do so but personally, I don't see the point.
And, yes, you're wrong about Python. I don't use it myself but I'm fully aware that Python+Django is more than equally capable of rapidly building Web sites as Ruby+Rails can.
JavaScript was developed by Netscape and Mozilla, and was originally called LiveScript. It was designed as a language for embedding live behaviors into HTML-based web pages by getting access to page elements and changing their values. It's a dynamically typed language that was originally suitable mostly to being programmable "glue" for sticking together and manipulating stuff that is really implemented in some other language that was more powerful and a lot faster.
Java was created by Sun Microsystems, now Oracle, at essentially the same time (both JavaScript and Java date to 1995), for the pu
JavaScript was developed by Netscape and Mozilla, and was originally called LiveScript. It was designed as a language for embedding live behaviors into HTML-based web pages by getting access to page elements and changing their values. It's a dynamically typed language that was originally suitable mostly to being programmable "glue" for sticking together and manipulating stuff that is really implemented in some other language that was more powerful and a lot faster.
Java was created by Sun Microsystems, now Oracle, at essentially the same time (both JavaScript and Java date to 1995), for the purpose of writing complete server and graphical applications, and for writing utilities. It was designed to be easily networked, to be operating system neutral, and to be powerful enough to write just about anything. It is also a strongly typed language roughly in the tradition of C, C++, and similar languages like Pascal and Modula-2, and has a nice clean class model that is much simpler than the model in C++. It lacks C and C++'s low level access to OS primitives and memory but is otherwise quite powerful and capable.
At some point, Sun started pushing the idea of running Java in browsers similarly to how LiveScript runs in browsers, but with what was at the time much richer graphics and animation capabilities, though lesser HTML integration.
For some reason that I still don't quite get, Netscape responded by renaming LiveScript to JavaScript. I guess the idea was to confuse the market into using its awkward and mildly ugly LiveScript language rather than the much cooler Java language.
There, that's the similarity between Java and JavaScript. They can both run in browsers, extending the raw capabilities of HTML, they are both computer languages, they were both invented at about the same time, and they both begin with the letters J, A, V, and A.
It's also true that they are both object oriented languages, but there aren't many modern languages that don't do objects, so that's not that meaningful, and they do objects fairly differently.
JavaScript has always had better browser integration, so if you are making live web pages using browser side coding, write JavaScript.
JavaScript has since been optimized to a remarkable degree, so it isn't such a terrible server side language, though for large projects you are almost certainly better off writing Java. You really want compile time type checking for large projects, and Java has quite a rich set of server-side tool libraries.
It would be easier to describe their similarities. Java is a compiled, statically and strongly typed language with runtime linking targeting the JRE. JavaScript is a weakly typed language normally interpreted (with some JIT compilation for optimization) and normally running in a web browser and until recently had no way to directly include/import additional files.
Java is a very object oriented language based on class inheritance. All code and variables are part of an object. JavaScript is much less so. It uses prototypal inheritance, though there is some class-like syntactic sugar in modern ve
It would be easier to describe their similarities. Java is a compiled, statically and strongly typed language with runtime linking targeting the JRE. JavaScript is a weakly typed language normally interpreted (with some JIT compilation for optimization) and normally running in a web browser and until recently had no way to directly include/import additional files.
Java is a very object oriented language based on class inheritance. All code and variables are part of an object. JavaScript is much less so. It uses prototypal inheritance, though there is some class-like syntactic sugar in modern versions of JavaScript. It is quite possible to program JavaScript like any non-object oriented, procedural language. JavaScript is also much more enthusiastic about casting from one type to another without the programmer asking for this, which leads to some odd and unexpected behaviors when you accidentally mix numerical values with string values as opposed to throwing an error.
Java has a very large defined runtime including support libraries/objects. The JavaScript language itself has few defined support functions. This is part of the reason the NPM eccosystem is so full of modules that are basically a single function, because these functions would be part of the standard support objects in the Java world.
JavaScript can (but won’t always depending on how they’re declared) hoist variables outside of the block that they’re defined in. In addition, JavaScript is happy to reference undeclared variables, assuming them to be properties on the global object.
They do both have syntax rather strongly based on C style syntax, and I’d actually say that most of the similarities between the two languages lie here.
- In DOM Tree each HTML element is called node.
- Object means properties with values.
- For example,
- This is Polacode extension from VSCode.
- In DOM Tree each HTML element is called node.
- Object means properties with values.
- For example,
- This is Polacode extension from VSCode.
No difference.
You can use quotes around the key to put special characters in the key. For example, neither of these are valid, and need quotes instead:
- { +: 1 }
- { :: 1}
These are correct:
- { "+": 1 }
- { ":": 1 }
Answers to such questions is that whichever language you mastered first is easier.
With that said, I did C++ and JavaScript before Ruby, and still think Ruby is perhaps slightly easier than JavaScript because of its more intuitive syntax. It is also more imperative / OO than JavaScript, which is more functional. But neither language is particularly 'hard’ if you have to compare with, say, Lisp. Rub
Answers to such questions is that whichever language you mastered first is easier.
With that said, I did C++ and JavaScript before Ruby, and still think Ruby is perhaps slightly easier than JavaScript because of its more intuitive syntax. It is also more imperative / OO than JavaScript, which is more functional. But neither language is particularly 'hard’ if you have to compare with, say, Lisp. Ruby is a very flexible language with a pretty easy syntax, not particularly hard to remember. It is OO, with a lot of interesting constructs for module reuse. If you stick to Douglas Crockford's ...
Nothing in c is an object
There are far more expressive and productive languages than Ruby that have native performance. Look at Haskell, Ocaml, etc.
The question is not dumb but it shows that you need to take a wider survey of the tools that exist.
I feel like I can finally answer a Quora question!
I have been learning JavaScript for about a year and I am now in a boot camp learning ruby. Javascript, in terms of the language as it is used today is harder. There are more gotchas. (hoisting, this, use of the semicolon)There are more use cases and edge cases. Ruby is built to make us “happy”, javascript was not. ;)
For a complete beginner javascript is easy to dive into. Use the console or jsfiddle or any of the other tools and just start learning.
Ruby does take some understanding of the command line and a bit more understanding of how your c
I feel like I can finally answer a Quora question!
I have been learning JavaScript for about a year and I am now in a boot camp learning ruby. Javascript, in terms of the language as it is used today is harder. There are more gotchas. (hoisting, this, use of the semicolon)There are more use cases and edge cases. Ruby is built to make us “happy”, javascript was not. ;)
For a complete beginner javascript is easy to dive into. Use the console or jsfiddle or any of the other tools and just start learning.
Ruby does take some understanding of the command line and a bit more understanding of how your computer works.
So ease of getting started goes to javaScript but...
Once you begin to learn the languages, oh ruby feels nice! There are a ton of pre-made methods for your convenience that javascript doesn’t have. Iterating over an array or hash(object in js) is easy.each{|a| a.upcase} !
Ruby is full-blown Object Oriented Programming.
Javascript is prototypal and functional… and um everything is an object… and also it’s not OOP but it also is. :/ There are also several "fixes" to javaScript that seem to be intended to make it more like other "better" languages. Many javaScript diehards would prefer it be left alone and people respect the prototypal paradigm that makes it unique, many others use TypeScript/babel because they can't live without classes. Don't think that javaScript isn’t awesome though. I think it gets a bad rap from people who don’t know it very well, but ruby is far more straightforward.
Edit:
I didn’t provide an answer about the importance of each language in web dev:
I would say JS is vastly more important to web dev. You may even NEED to know javaScript(typeScript, coffeeScript, elm, jQuery, etc.) to do web development. You most certainly do not NEED to know ruby.
Java is a statically-typed, classically-object-oriented language developed for enterprise software by Sun Microsystems.
JavaScript is a dynamically-typed prototypically-object-oriented language developed in a week for Netscape to let people add basic scripted behaviors to web pages.
They have about as much in common as a car has with a carpet.
This is something I've been thinking a lot about lately.
Javascript on one hand, represents the idea of rapid prototyping that scales, and Node.js has sort of catapulted JS into the hard tech spotlight. Now we have V8, we have TurboFan, we have Chakra, we have all this great technology to keep improving this language that was never meant to be, from some points of view. I don't particularly care fo
This is something I've been thinking a lot about lately.
Javascript on one hand, represents the idea of rapid prototyping that scales, and Node.js has sort of catapulted JS into the hard tech spotlight. Now we have V8, we have TurboFan, we have Chakra, we have all this great technology to keep improving this language that was never meant to be, from some points of view. I don't particularly care for Javascript but it represents a departure in how programs were written before it, and I quite enjoy seeing some of the innovative minds go to work, even with something as irritating as js. It's amazing in some regards what people have managed to make with it.
Anyways, the ECMAscript spec has now incorporated a class keyword that wraps around the standard prototyped object model, there's languages like Dart that use a much saner object model and can compile down to js to run in the browser. This brings me into my next point: WebAssembly might change everything.
If WebAssembly is a huge hit, than it will represent the potential for a new era of web programming where the language you choose no longer has much meaning. If we are able to transpile from a language right down to wasm, and run it in the browser at native speeds, it won't matter how slow the original language was, so long as it produces efficient code for wasm.
But wait, what about Ruby? Well, I like Ruby quite a bit. I've been using Ruby off and on for small scripts and automation projects, and I've managed to never have to touch or learn Rails throughout all this time. In fact, I've never really touched web development at all!
Opal.rb makes it possible to compile Ruby to JS, but I've not spent much time with it because most of the underlying tech behind a webpage is alien to me. I don't know all my HTML tags by heart, I only know what a CSS selector is because I just googled it, and it would take me a few minutes to fumble enough Javascript together to actually do stuff.
I think Ruby suffers a bit from the Rails project taking so much spotlight from the Ruby language itself. Ruby suffers from weak concurrency controls, and too much reliance on dynamic features.
Luckily, the Crystal language fixes most of this crap, and runs on top of the LLVM, blazing-fast performance nearly on par with plain ol' C.
The astute reader might realize that Crystal therefore abandons the ability to use Opal, and therefore is farther away from JS, and farther away from WebAssembly.
For now, all I know for sure is that if LLVM IR is ever translatable to WebAssembly, than we all win. Lots of languages run on LLVM, and if it was possible to just add an extra compiler flag to crap out a webpage, I'm sure there would be plenty of people eager to do so.
So, tying this all back together: Will they still be relevant? I think Javascript has a pretty good chance of being relevant, especially if future versions of the spec start moving towards abstracting class-based models on top of the current object mode, I think that's a genius move. As for Ruby, it's an uncertain time right now, and I'm not sure that slow ol' Ruby is going to make it to the next generation of modern languages. Crystal might exist for a little while, but without that web aspect, it will on...
If your friend can program in some other language already, it really doesn't matter if he starts with Ruby or JavaScript first. Note the key words here are 'start' and 'first'. If he can already code and understands how to write a piece of software, in particular to the web, he can and should pick up both of them. However they are quite different syntax and concept wise so the learning curve of each depends on what he knows already, and the learning curve for both in general depends on how well he knows 'programming' in general. The underlying concepts of writing code are the same across all
If your friend can program in some other language already, it really doesn't matter if he starts with Ruby or JavaScript first. Note the key words here are 'start' and 'first'. If he can already code and understands how to write a piece of software, in particular to the web, he can and should pick up both of them. However they are quite different syntax and concept wise so the learning curve of each depends on what he knows already, and the learning curve for both in general depends on how well he knows 'programming' in general. The underlying concepts of writing code are the same across all languages and you can find a common base even across languages that are polar opposite in their philosophy. Ultimately your goal in this game is to break down big problems into smaller ones using abstractions.
If he knows nothing or is at a lower level, I'd suggest starting with Ruby as its syntax is easier on the eyes. Another idea is that Mr. Friend should pick a first project and then choose the language based on the project's needs. He'll likely to end up using both.
I think Ruby is easier to learn.
The reason why, is I think the language has a lot of good conventions that make it easier to remember.
For example:
- member functions that return True/False end in a ?
- x.nil? means “is x nil?”
- member functions that destructively change their object
- y = x.sort! means x will be now sorted. x and y point to the same object.
- y = x.sort means a copy of x is stored and will be stored in y. x and y are distinct objects
Also you can dynamically query an object to find stuff about it.
- myObject.class - returns the class
- myObject.methods - returns the methods (member functions) that
I think Ruby is easier to learn.
The reason why, is I think the language has a lot of good conventions that make it easier to remember.
For example:
- member functions that return True/False end in a ?
- x.nil? means “is x nil?”
- member functions that destructively change their object
- y = x.sort! means x will be now sorted. x and y point to the same object.
- y = x.sort means a copy of x is stored and will be stored in y. x and y are distinct objects
Also you can dynamically query an object to find stuff about it.
- myObject.class - returns the class
- myObject.methods - returns the methods (member functions) that myObject knows about.
Here is my thought, but this can't be same with others expertise and experience, but from my opinion I am answering your question, if you like this, then don't forget to share with your friend :
Pros of Ruby:
1. Elegant Syntax: Ruby is known for its clean and elegant syntax, which makes it easy to read and write. This promotes developer productivity and code maintainability.
2. Rich Ecosystem: Ruby has a robust ecosystem of gems and libraries that simplify many development tasks. This saves time and effort in building various functionalities.
3. Strong Community: Ruby has a passionate and supporti
Here is my thought, but this can't be same with others expertise and experience, but from my opinion I am answering your question, if you like this, then don't forget to share with your friend :
Pros of Ruby:
1. Elegant Syntax: Ruby is known for its clean and elegant syntax, which makes it easy to read and write. This promotes developer productivity and code maintainability.
2. Rich Ecosystem: Ruby has a robust ecosystem of gems and libraries that simplify many development tasks. This saves time and effort in building various functionalities.
3. Strong Community: Ruby has a passionate and supportive community of developers. This means you can find help, tutorials, and resources easily.
4. Rails Framework: Ruby on Rails, a popular web framework, is known for its rapid development capabilities, making it a go-to choice for building web applications. There are some top websites those are running with Ruby on rails web framework, like: Spotify, Hulu, Fiverr, AirBnb, GitHub etc.
5. Object-Oriented: Ruby is a pure object-oriented language, which means everything in Ruby is an object. This simplifies code structure and promotes a consistent approach to programming.
Cons of Ruby:
1. Performance: Ruby can be slower compared to some other languages like JavaScript. This can be a drawback for applications requiring high performance.
2. Concurrency: Ruby's Global Interpreter Lock (GIL) can hinder concurrency, making it less suitable for CPU-bound tasks.
3. Limited Mobile Development: While Ruby can be used for mobile app development (e.g., RubyMotion), it's not as common as other languages like JavaScript for this purpose.
Pros of JavaScript:
1.Ubiquity: JavaScript is the primary language for web development, making it essential for front-end and back-end development with Node.js. This ubiquity ensures wide adoption and support.
2. Performance: JavaScript engines have improved significantly in recent years, providing competitive performance for web applications.
3. Versatility: JavaScript can be used for web development, mobile app development (React Native), desktop applications (Electron), and even server-side development (Node.js).
4. Large Community: JavaScript has a vast and active community, resulting in extensive documentation, libraries, and frameworks like React, Angular, and Vue.js.
Cons of JavaScript:
1. Inconsistencies: JavaScript has quirks and inconsistencies, which can lead to unexpected behavior if not handled carefully.
2. Callback Hell: In asynchronous code, JavaScript can suffer from callback hell, making code harder to read and maintain. However, modern JavaScript has addressed this with async/await.
3. Security Risks: Client-side JavaScript can be vulnerable to security threats like Cross-Site Scripting (XSS) if not properly secured.
Remember to discuss this with others person before shifting your jobs, based on my expertise and the knowledge I have shared this answer. Thanks for looking.
- Yes, since Javascript is the only programming language a web browser can run.
- If you know programming, it’s easy. If you don’t it’s anywhere from extremely difficult (you’re trying to learn a tool to do something you don’t know how to do - Javascript is just a tool to do programming with) to impossible. (So, if you don’t, learn programming itself first, and stop learning languages. Knowing a dozen programming languages doesn’t make you a programmer - knowing programming, without knowing any programming languages, does.)
Basics
Functions in JavaScript are first class citizens: they can be assigned to variables and can be freely moved around:
- var printer = function() {
- console.log(‘it works!’);
- }
- var delegator = function(func) {
- func();
- };
- # prints "it works!"
- delegator(printer);
The same is true for when a function is not assigned to a variable. It can still be referenced the same way as if it was a variable:
- function printer() {
- console.log(‘it works!’);
- }
- var delegator = function(func) {
- func();
- };
- # prints "it works!"
- delegator(printer);
In Ruby, blocks are not first class citizens - they are special language construc
Basics
Functions in JavaScript are first class citizens: they can be assigned to variables and can be freely moved around:
- var printer = function() {
- console.log(‘it works!’);
- }
- var delegator = function(func) {
- func();
- };
- # prints "it works!"
- delegator(printer);
The same is true for when a function is not assigned to a variable. It can still be referenced the same way as if it was a variable:
- function printer() {
- console.log(‘it works!’);
- }
- var delegator = function(func) {
- func();
- };
- # prints "it works!"
- delegator(printer);
In Ruby, blocks are not first class citizens - they are special language constructs which are meant to complement the functionality of regular methods. They are not objects (unlike most Ruby constructs), so they can’t be moved around or be referenced outside of their owner methods, and they don’t respond to any methods of their own.
Every method in the Ruby language is able to receive an implicit block. Unfortunately, not much can be done with the block except for calling it before it falls out of scope.
- def delegator
- # runs the block
- puts yield.class
- # also runs the block
- yield
- end
- # prints "String" and "it works!"
- delegator do
- puts 'it works!'
- 'a string'
- end
Here you can see that the yield
keyword calls out the block, which falls out of scope after delegator
runs.
Blocks are intrinsically coupled to methods, but this is part of why Ruby is so unique. We can probably say that each method owns its block. Note that blocks can easily be converted into procs or lambdas in order to have a similar flexibility as that of JS functions.
Lexical scope
JavaScript functions are able to access variables from the outer scope. Any variables around at definition time (that is, run time) can be accessed.
- var a = 'a';
- function callbackProvider() {
- var b = 'b';
- return function callback() {
- var c = 'c';
- console.log(a, b, c);
- }
- }
- var callback = callbackProvider();
- # prints a, b, c
- callback();
Scope access is outward-oriented, thus inward variables are never visible. For instance, callbackProvider
is not able to access the c
variable, which is defined inside the nested callback
function — but it’s able to access a
and b
.
Ruby blocks have similar lexical scope rules, in the sense that they hold a reference to the outer scope.
- a = 'a'
- def delegator
- yield
- end
- # prints "a"
- delegator do
- puts a
- end
Similarly to JavaScript, variables defined from within blocks are not accessible to the outside:
- run_me do
- b = 'b'
- end
- puts b # fails
We can conclude that a block created from within a method shares the same scope as the method plus a scope of its own. The same applies for when the block is contained by other language constructs such as classes.
- c = 'c'
- def other_method
- d = 'd'
- yield
- end
- def my_method
- a = 'a'
- other_method do
- puts a
- # neither of these variables exist here
- puts c
- puts d
- end
- end
- # prints a and fails
- my_method
Our block is not able to access d
, neither can it access the outer c
variable because of method scope rules. It can only access the same that's available to my_method
.
Arity
Neither blocks nor functions have strict arity requirements, so they accept any number of arguments (including no arguments).
- function myFunction(arg1) {
- console.log(arg1, arguments);
- }
- # prints 3 and { '0': 3, '1': 4 }
- myFunction(3, 4);
In this JavaScript example we called myFunction
with two arguments, but myFunction
only has one argument in its arg list.
Nevertheless, we can still access the arguments by means of the special arguments
object.
This is bad for JavaScript because function
is the only construct provided by the language to hold and execute code. We must manually check the arguments should we want to ensure arity in JavaScript functions.
Ruby blocks share the same dynamic essence as JavaScript functions:
- def delegator
- yield 'a'
- end
- delegator do |var1, var2|
- puts var1 # prints 'a'
- puts var2 # prints nil
- end
Note that the delegator
method calls the incoming block with one argument, even though the block lists out two arguments.
The block could even be called with three arguments, but delegator
would not able to access the third one. Unlike in JavaScript, we don’t have a way to access all arguments unless we explicitly allow the block to do so:
- def delegator
- yield ‘a’, ‘b’, ‘c’
- end
- delegator do |*args|
- # prints a, b, c
- puts args
- end
Here we are using a splat (language construct) as the first argument in order to catch all arguments.
Shadowing
A variable can be shadowed in JS functions and in Ruby Blocks as well. If you define a variable in a block or function and an outer variable with the same name exists, the block or function won’t be able to be access or modify it.
The shadowed variable takes precedence over the outer one inside the block or function, and the outer one is preserved intact.
Conclusion
JavaScript functions and Ruby blocks are very similar. The main difference between them regards flexibility — as the former is a first class citizen and can be used in many more ways. Fortunately, Ruby offers procs and lambdas to overcome this fundamental limitation, which we will not discuss about here.
Couple of points.
1. Javascript can be used not only for client side but also as a server side programming language but currently mainly used for client side operations.
If you want a complete javascript stack for application look at something like
SocketStream: http://www.socketstream.org/
2. Learning curve
Javascript - It depends on what you are trying to do with
- do you need to use it more for client side operations, then learning the basics and using any of Javascript library like Jquery, ExtJS, Prototype etc is easy. You do not need to worry of handling cross browser c
Couple of points.
1. Javascript can be used not only for client side but also as a server side programming language but currently mainly used for client side operations.
If you want a complete javascript stack for application look at something like
SocketStream: http://www.socketstream.org/
2. Learning curve
Javascript - It depends on what you are trying to do with
- do you need to use it more for client side operations, then learning the basics and using any of Javascript library like Jquery, ExtJS, Prototype etc is easy. You do not need to worry of handling cross browser compatibility issue.
- Debugging javascript is harder compared to ruby.
Ruby - It might look simple from outside but it is like a swiss knife.
It is really strong in terms of meta-programming, too dynamic and supports multiple paradigms like it is imperative, functional and object oriented.
The complexity increases depending on the use of different features of the language, the more dynamic code : more complexity.
From my perspective Ruby is more complex than Javascript.
3. Importance in web-development:
Both have their own use and advantage depending on the application.
Javascript
If you need a simple application which has lot of user operation on the client side then the entire application can be built using complete JS stack.Other general uses
- Interactive UI
- Form/data validation
- Creating funky/cool UI
Security and Cross browser compatibility are some of its drawbacks
Ruby
If the application is much more than that then using different frameworks, like Sinatra, Rails etc involves using ruby. For using any of these frameworks you do not actually need to learn ruby to the core but i feel learning and understanding the basic concepts, strength & weakness of a language is really important.
There are many web frameworks around which uses ruby as core ROR, Merb etc.
The importance of ruby is more on server side and javascript on client side.
OO is a style of programming, not just a language construct
At it's core, object-oriented programming is about representing related bits of data and functionality into named chunks called objects, and then writing your code in such a way that it's easy for humans to interact with it. It's a way of organizing your code so that future developers can make sense of things easily, and hence it keeps the cost of development low.
Certain programming languages such as Ruby, Java and JavaScript have language constructs that make it possible for you to write code in an object-oriented fashion, some more
OO is a style of programming, not just a language construct
At it's core, object-oriented programming is about representing related bits of data and functionality into named chunks called objects, and then writing your code in such a way that it's easy for humans to interact with it. It's a way of organizing your code so that future developers can make sense of things easily, and hence it keeps the cost of development low.
Certain programming languages such as Ruby, Java and JavaScript have language constructs that make it possible for you to write code in an object-oriented fashion, some more easily than others. Other languages, like Haskell make it more difficult to write (and in some cases impossible) to write code in an OO fashion.
So you can write functional-style programs in both languages, or OO-style programs in both languages.
Objects and methods
To start, Ruby and JavaScript both share the concept of there being Objects, and being able to call methods on those objects. Syntactically both use the dot notation (`object.method`) to call methods on objects, so it might seem like they are more similar than they actually are.
In Ruby methods truly do belong to objects, and can only be called on those objects. In JavaScript "methods" are really just short-hand for looking up the correct function to call, and passing in the object as `this`. So the following two calls are identical in JavaScript:
- var person = {
- fullName: function(){
- return [this.firstName, this.lastName].join(' ');
- };
- }
- person.fullName(); // is the same as...
- person.fullName.call(person);
So in Ruby you have to invoke a method on an object. In JavaScript you just have functions, and if you call a function on an object it will afford you some benefits.
Inheritance
Inheritance deals, in part, with method lookup. Ruby and JavaScript both have built-in support for calling methods up-the-chain, so to speak, but they implement it very differently.
Take the following Ruby:
- class Person
- attr_reader :first_name, :last_name
- def initialize(first_name, last_name)
- @first_name = first_name
- @last_name = last_name
- end
- def full_name
- "#{first_name} #{last_name}"
- end
- end
- Person.new('Jeff', 'Dean').full_name
When you call the `full_name` method on your new Person instance, it looks at itself, at Person and then at any class Person inherits from (in this case Object, Kernel, BasicObject etc...). This is what you'd call an "is-a" relationship - your object is a Person. The `full_name` function can only be called on a person, or another object that's a subclass of Person.
In JavaScript, a reasonable approximation of this would be:
- var Person = function(firstName, lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- };
- Person.prototype.fullName = function(){
- return [this.firstName, this.lastName].join(' ');
- };
- new Person('Jeff', 'Dean')
But rather than creating an "is-a" relationships, when you use the `new` keyword, it effectively does this:
- var person = {} // plain old javascript object
- Person.call(person, 'Jeff', 'Dean') // call the Person function, passing in our new object as `this`
- person.prototype = Person // (pseudo-code) - point our `person` object to another Object where functions might be defined
- return person;
Note that what comes out of `new Person()` is just a plain old JavaScript object - but it has one special property set - the `prototype` property. So when you call `person.fullName()` it looks at itself first, then goes to its prototype, then its prototype's prototype etc... JavaScript uses prototypes to find the right function to call, then it uses the fact that `object.foo()` is the same as `object.foo.call(object)` to make it appear as if it's doing the same thing that Ruby is doing.
So method lookup can feel similar in both languages, even though their exact details are quite different.
Super
Ruby has proper support for `super` - that is, when you override a method, you can internally call your super-class's method with the same name. JavaScript does not have a built-in concept of super, although you can create your own fairly trivially (see Invoking Super Methods in JavaScript (http://blog.salsify.com/engineering/super-methods-in-javascript)).
This is one of the biggest differences in the two.
Encapsulation
Ruby has the concept (although a bit strange) of hiding methods and instance variables. Ruby has a concept of public, protected and private methods, with the latter two being a little harder to call on objects. It also has the concept of instance variables which should, in theory, only be accessed by methods on that class. As with everything in Ruby, there are ways to get around it, but Ruby clearly supports the intent of the developer to make things hidden from the outside world.
In JavaScript there are no built-in concepts of private functions or private attributes that you can use in a declarative way (like `public :foo`), so many people think you can't encapsulate data, but it does allow you to hide data well if you know how (Private Members in JavaScript).
Polymorphism
Both Ruby and JavaScript have types, but don't enforce them. For example you can't make either language enforce that you pass a string to a method. So in both languages you can rely on duck-typing - basically writing methods such that if an object has the right methods / properties your code will work ("if it walks like a duck and quacks like a duck"...)
This makes polymorphism super easy, and you won't notice much of a change for most parts of your program if you are actually using polymorphism well. However, Ruby allows you to ask an object for its type (`person.is_a?(Person)`) whereas JavaScript's typeof will always return "object" for your "instances". So if you rely heavily on that kind of asking you'll have to hand-roll it in JavaScript.
Yes. Javascript is not related to Java although their name sounded the same. Java is an object oriented language used for Android applications and structures that need a powerful language. Javascript on the other hand is used mostly in web development. It has other uses but that is the most popular.
Just as the question is posed, it is difficult for the person who asked it to understand the answer.
- They are all programming languages, (all).
- Only C ++ is compiled into machine language (binary)
- Java and Python are converted to intermediate code before running
- Less C ++, the others have JITs
- Python and Ruby are also considered scripting languages.
- I have not found references to PHP being a scripting language (although by the definition of a scripting language, it could be).
In general, a scripting language is one that allows making small programs (generally of the imperative type) that are executed
Just as the question is posed, it is difficult for the person who asked it to understand the answer.
- They are all programming languages, (all).
- Only C ++ is compiled into machine language (binary)
- Java and Python are converted to intermediate code before running
- Less C ++, the others have JITs
- Python and Ruby are also considered scripting languages.
- I have not found references to PHP being a scripting language (although by the definition of a scripting language, it could be).
In general, a scripting language is one that allows making small programs (generally of the imperative type) that are executed with an interpreter. In that case, the only one that wouldn't be scripting is Java (I didn't find any indications that this is the case).
The simplicity of a program could be based (incomplete) to determine if a language is scripting.
Example a program to write Hello World!
C++
- #include <iostream>
- using namespace std;
- int main() {
- std::cout << "Hello World!";
- return 0;
- }
Java
- public class Program {
- public static void main(String[] args) {
- System.out.println("Hello World!");
- }
- }
JavaScript
- document.write('Hello World!');
PHP
- <?php
- echo "Hello World!";
- ?>
Python
- print "Hello World!"
Ruby
- puts "Hello World!"