When comparing Ruby vs Go, the Slant community recommends Go for most people. In the question“What is the best programming language to learn first?” Go is ranked 2nd while Ruby is ranked 10th. The most important reason people chose Go is:
The language is designed in a manner that seems logical. Syntax is simplified to reduce burden on the programmer and compiler developers.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Widely used
Ruby is one of the most popular languages for developing web sites. As a result, there's an abundant amount of documentation, sample code, and libraries available for learning the language and getting your project up and running. The most popular features are just 'gem install' away. Additionally, it is easier to find Ruby jobs because of this.
Pro Clean syntax
Ruby has a very clean syntax that makes code easier to both read and write than more traditional Object Oriented languages, such as Java. For beginning programmers, this means the focus is on the meaning of the program, where it should be, rather than trying to figure out the meaning of obscure characters.
presidents = ["Ford", "Carter", "Reagan", "Bush1", "Clinton", "Bush2"]
for ss in 0...presidents.length
print ss, ": ", presidents[presidents.length - ss - 1], "\n";
end
Pro A large ecosystem of tools & libraries
Ruby has a large ecosystem of tools and libraries for just about every use. Such as ORMs (Active Record, DatabMapper), Web Application Frameworks(Rails, Sinatra, Volt), Virtualization Orchestration(docker-api, drelict), CLI tools(Thor, Commando), GUI Frameworks(Shoes, FXRuby) and the list goes on. If you can think of it, there is probably a gem for that ( and if not you can create your own and share with the community).
Pro Newbie-friendly community
Pro Essential algorithmic features
The Ruby language is equipped with the necessary features to learn the essence of algorithms.
In online playground environments like ideone.com, measures have been taken to prevent beginners from going astray by restricting the use of external libraries such as Python's NumPy and SymPy.
Even in such constrained Ruby execution environments, the required features for learning algorithms are fully available.
Many of the algorithms that should be learned are documented in the book "Hello Ruby: Adventures in Coding." For example, the cake serving problem in the book leads to topological sorting, which is a graph theory concept useful in project management for creating Gantt charts.
To evaluate the effectiveness of algorithms with a level of complexity comparable to topological sorting,
it is necessary to be able to solve mathematical computation problems up to the high school level easily.
As shown in the table below, using only Ruby's standard library, it is possible to solve high school-level math problems effortlessly.
However, other programming languages may not be able to perform such computations in online playground environments.
To experience the superior performance of algorithms, it is important to challenge oneself by reimplementing good algorithms. Ruby's standard library includes implementations of excellent algorithms. For instance, the algorithm for solving linear equations, which has been widely known since the era of Fortran, is used within the code of SolvingLinearEquations through the "/" operator. Reimplementing code from Ruby's standard library serves as an excellent learning resource with high reusability and efficiency.
The SolvingLinearEquations function mentioned above demonstrates the benefits of duck typing and forced type conversion between objects of different types in arithmetic operations. While Rust also has features like duck typing, the implementation of "forced type conversion" is still far from being realized.
Mathematical Problem Type | Ruby Standard Library | Python Standard Library |
---|---|---|
Long Integer and Fraction | ✓ | ✓ |
Long Integer and Complex Fraction | ✓ | ✖ |
Operations on Matrices with Multiple-Digit Numbers as Coefficients | ✓ | ✖ |
Solution of Integer Coefficient Systems of Equations | ✓ | ✖ |
Solution of Systems of Equations with Long Integer and Complex Fraction Coefficients | ✓ | ✖ |
Solutions of Linear Equations with Real, Fraction, Complex, and Complex Fraction Coefficients | ✓ | ✖ |
# Title: "(1) Cake Serving Procedure Problem"
require 'tsort'
class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end
puts 'Tasks'
task_names = {
'A' => 'Arrange the plates.',
'B' => 'Set the spoons.',
'C' => 'Place the birthday cake on the table.',
'D' => 'Spread the tablecloth.'
}
p task_names
puts 'Preceding Tasks'
preceding_tasks = {
'A' => ['D'],
'B' => ['C', 'A'],
'C' => ['A', 'D'],
'D' => []
}
steps = preceding_tasks.strongly_connected_components
puts 'The appropriate steps are as follows:'
steps.each do |task_candidates|
p task_candidates.map { |task| [task, task_names[task]] }
end
p "#(2) Equation Solving Rule"
def SolvingLinearEquations(y, a, b)
x = (y - b) / a
end
p "(2-1) Real Solution", SolvingLinearEquations(1.0, 5, 0.5)
# => 0.1
p "(2-2) Fraction Solution", SolvingLinearEquations(Rational(1, 1), Rational(5, 1), Rational(1, 2))
# => (1/10)
p "(2-3) Imaginary Solution", SolvingLinearEquations(1 + 1i, 5, 1.0 / (2 + 2i))
# => (0.15+0.25i)
p "(2-4) Complex & Fraction Solution", SolvingLinearEquations(Rational(1 + 1i, 1), Rational(5, 1), Rational(1, 2 + 2i))
# => ((3/20)+(1/4)*i)
p "(2-5) Matrix Solution with Large Integers",
SolvingLinearEquations(Matrix[[Rational(1234567890123456789890, 1), Rational(0, 1)]],
Matrix[[Rational(1234567890123456789890, 1), Rational(1234567890123456789890 * 2, 1)],
[Rational(1234567890123456789890, 1), Rational(1234567890123456789890 * 3, 1)]],
Matrix[[Rational(1234567890, 1), Rational(123456789, 1)]] )
# => Matrix[[(3703703670366790122789/1234567890123456789890), (-2469135780244567900789/1234567890123456789890)]]
p "(2-7) Matrix Solution with Large Integers, Complex Numbers, and Fractions",
SolvingLinearEquations(Matrix[[Rational(1234567890123456789890, 1i), Rational(0, 1)]],
Matrix[[Rational(1234567890123456789890, 1), Rational(1234567890123456789890 * 2, 1i)],
[Rational(1234567890123456789890, 1), Rational(1234567890123456789890 * 3, 1i)]],
Matrix[[1234567890, 0 + 1i]] )
# => Matrix[[((-3703703671/1234567890123456789890)-(3/1)*i), ((2469135781/1234567890123456789890)+(2/1)*i)]]
Pro Ruby on Rails
Lays out an easy to follow and opinionated MVC pattern that teaches best practices through necessity.
Pro Test Driven Development, #1
It's the fore-runner and trend setter for TDD.
Pro Hugely object oriented
Object oriented programming is one of the most important concepts in programming.
Pro Meta-programming
Meta-programming provides efficiency and freedom.
Pro No indentation
No indentation increase development efficiency.
Pro Pry
Pro Simplified C-like syntax that is as easy to read and write as Python
The language is designed in a manner that seems logical. Syntax is simplified to reduce burden on the programmer and compiler developers.
Pro Great team working behind it
Go has a solid team of engineers working on it (some of the best networking engineers in the world are working on Go). Up until now, the great engineering of the language has compensated for its lack of power.
Pro Easy to install and configure; simple to compile software
Go software can be immediately installed, regardless of your operating system, package manager, or processor architecture with the go get command. Software is compiled statically by default so there is no need to worry about software dependencies on the client system. Makefiles and headers are no longer necessary, as the package system automatically resolves dependencies, downloads source code and compiles via a single command: go build
.
Pro Programmers don't have to argue over what 10% subet of the language to implement in their software project
The language promotes programming in a specific idiomatic style, which helps keep every programmer on the same page.
Pro Supports 'modules' in the form of packages
Every Go source file contains a package line that indicates which package a file belongs to. If the name of the package is 'main', it indicates that this is a program that will be compiled into a binary. Otherwise, it will recognize that it is a package.
Pro Demonstrates a unique, simple concept to object-oriented programming
All types are essentially objects, be they type aliases or structs. The compiler automatically associates types to their methods at compile time. Those methods are automatically associated to all interfaces that match. This allows you to gain the benefits of multiple inheritance without glue code. As a result of the design, classes are rendered obsolete and the resulting style is easy to comprehend.
Pro Great language for building networking services
Go was started as a systems language but now it has fully committed in the niche of networking services. This has been a brilliant move by Go because it allows them to capitalize on the immense talent of the Go engineering team (who are in the most part network engineers).
In a world dominated by Java EE and slow scripting language, Go was a breath of fresh air and it continues to be one of the most powerful languages if you want to build networking services.
Pro Exceptionally simple and scalable multithreaded and concurrent programming
Goroutines are "lightweight threads" that runs on OS threads. They provide a simple way for concurrent operations — prepending a function with go
will execute it concurrently. It utilizes channels for communication between goroutines which aids to prevent races and makes synchronizing execution effortless across goroutines. The maximum number of OS threads goroutines can run on may be defined at compile time with the GOMAXPROCS
variable.
Pro The go compiler compiles binaries instantly — as fast as a scripting language interpreter
Compiled binaries are fast — about as fast in C in most cases. Compiles on every OS without effort — truly cross-platform compiler. As a result of the fast compilation speed, you can use the gorun program to use go source code as if it was a scripting language.
Pro Performance is on the order of C and Java
Go is blazing fast, but easier to write than Python, JS, Ruby, or many other dynamic languages.
Pro Jobs available
You can find a Job knowing Go. Which is more than can be said with many other languages.
Pro API documentation is rich in content; easy to memorize
Only features deemed critical are added to the language to prevent cruft from working its way into the language. The language is small enough to fit inside one's head without having to repeatedly open documentation. Documentation is hosted on an official webpage in a manner that is simple to read and understand.
Pro Supports functional programming techniques such as function literals
This naturally also supports first class and high order functions, so you may pass functions as variables to other functions.
Pro Multiple variables may be assigned on a single line
This conveniently eliminates the need to create temporary variables.
Fibonacci example: x, y = y, x+y
Pro Built-in unit testing
The idiomatic approach to writing a Go software project is to perform test-driven development with unit testing. Every source code file should have an associated *_test.go
file which tests functions in the code.
Pro Provides tools for automatically formatting code for your entire software project
This helps keep every programmer on the same page in a project and eliminates arguments over formatting styles.
Pro Automatically generates API documentation for installed packages
Godoc is provided to automatically generate API documentation for Go projects. Godoc also hosts its own self-contained web server that will list documentation for all installed packages in your Go path.
Pro Supports splitting source code into multiple files
As long as every source code file in a directory has the same package name, the compiler will automatically concatenate all of the files together during the compilation process.
Pro Syntax for exported code from a package is simplified to be less verbose than other languages
Any variable, type and function whose name begins with a capital letter will be exported by a project, while all other code remains private. There is no longer a need to signify that a piece of code is 'private' or 'public' manually.
Cons
Con Monkeypatching
Requiring a library can change the rules of the language. This is very confusing for beginners.
Con Its ecosystem is limited outside of web development
If you're looking to host, generate, manipulate or secure a website, Ruby is your language. There's also some great support here for infrastructure as code work via Chef. However, it just doesn't have the depth and breadth that Python does. Things like native UI development, high performance math, and embedded / small footprint environments are barely supported at all in Ruby-space.
Con Arcane grammar based on Perl
Ruby is too complicated for beginners:
- arcane Perlisms;
- semi-significant whitespace;
- parentheses are not necessary around method arguments, except for sometimes they are;
- control constructs could be elegantly implemented with block like Smalltalk (Instead they're baked into the grammar.);
- verbose block syntax, unless it happens to be the last argument. (proc lambda).
- There are too many exceptional cases and arcane precedence rules.
Con Meta-programming causes confusion for new developers
The ability for libraries to open classes and augment them leads to confusion for new developers since it is not clear who injected the functionality into some standard class.
In other words, if two modules decide to modify the same function on the same class can introduce a number of issues. Mainly, the order in which the modules are included matters. Since you more or less can't tell what kind of "helper" functions a module might write into any class, or for that matter, where the helper function was included from, you may sometimes wonder why class X can do Y sometimes but not at other times.
Con No docstrings
It's hard to access Ruby's documentation from the REPL (irb), unlike Python, Lisp, and Smalltalk which let you ask functions how to use them, which is a great benefit to the beginner, and which also encourages you to document your program as you code it.
Con More than one way to do it
A problem inspired by Perl. The core API interfaces are bloated. There's at least four different ways to define methods. More is not always better. Sometimes it's just more.
Con Does not teach you about data types
Since Ruby is a dynamically typed language, you don't have to learn about data types if you start using Ruby as your first language. Data types being one of the most important concepts in programming. This also will cause trouble in the long run when you will have to (inevitably) learn and work with a statically typed language because you will be forced to learn the type system from scratch.
Con Dynamic type system
Majority of bugs could be resolved with types.
Con Viewed as a web development language
Despite its flexibility and performance, Ruby is often seen as being unsuitable for other tasks by those who are not familiar with it. As such, a lot of discussion about it centers around Rails, which is not at all relevant if you're using Ruby for something else, such as game development.
Con Focus on Object-Oriented Programming (OOP)
Focussing on OOP in a beginner stage is an easy and popular plan, but not the best one.
Con Golang controlled by Google
Solves Google problems, which might not be your or the majority of user's problems. Was created for the benefit and purposes of Google, so is less flexible in language direction and options.
Con Hard to abstract even the simplest notions
Go is famously regarded as very simple. However, this simplicity becomes problematic in time. Programmers who use Go find themselves over and over again writing the same thing from a very low point of view. Domains not already served by libraries that are easy to glue are very difficult to get into.
Con Forces K&R style and won't allow Allman style
Golang developers were extremely short-sighted and biased by forcing the K&R style, which should never have happened. Basically kicking Allman style users out of their language.
Con Doesn't have true enums
Golang does weirdness with const versus having real enums, like other languages. This reflects the stubbornness and shortsightedness of the core developers, similar to the issue with generics, where it was denied that it was needed until it became too obvious that it should have been added years ago.
Con Does not have sum types
Makes it harder to have functions of different parameters types in a non OOP language. Thus messy generics and interfaces, and more confusion, where sum types could have solved a number of issues.
Con It appears Google uses position to snuff out or suppress other languages
Newer languages that could threaten Golang (or other Google controlled languages) appear to have suppressed search results on Google and YouTube. Dangerous situation where large company can manipulate user choice and market share. The freedom to freely choose and user rights need to be protected.
Con Designed to make the programmer expendable
Go was designed for large team projects where many contributors may be incompetent. That Go can still get things done under these conditions is a testament to its utility in this niche. Go's infamously weak abstraction power is thus a feature, not a bug, meant to prevent your teammates from doing too much damage. This also means any team member can be easily replaced by another code monkey at minimum cost. Good for the company, bad for you. The more talented programmers, on the other hand, will be very frustrated by having one hand tied behind their back.
Con Easy to shadow variable
Due to single character only difference, declare and assign statement can easily shadow variable from outer scope unconsciously. Example:
err := nil
if xxx {
err := somefunctionthatreturnsanerr
}
return err // always return nil
Con No forms designer
Those who are used to Visual Studio can feel the lack of a forms designer for rapid development.
Con Bizarre syntactic choices like a unique date format.
Con Changing visibility requires renaming all over the code
Con Lacks support for immutable data
Only way to prevent something from being mutated is to make copies of it, and to be very careful to not mutate it.
Con Performance slowdown because of indirect calls and garbage collection
Practically no meaningful Go application can be written without indirect function calls and garbage collection, these are central to Go's core infrastructure. But these are major impediments to achieving good performance.
Con Implementation of interfaces are difficult to figure out
Finding out what interfaces are implemented by a struct requires a magic crystal ball. They are easy to write, but difficult to read and trawl through.