Web apps in Ruby or PHP? HOW TO SOLVE POPULAR DILEMMA? :)

Customers often have to decide, in which programming language they would like their product to be created. Ruby and PHP are on of the most common dilemma. Inspire of PHP’s former popularity, recently more and more customers are reporting their need to create products using Ruby and its popular Ruby on Rails framework.

In Codest we had the opportunity to cooperate with many clients that require proper arguments, why the programming language offered by the software house will be a good choice for their productQuite often the dilemma concerns Ruby and PHP. We exactly know that PHP is better known for most people. However, the market trend is different. Ruby has many of strengths that customers and developers appreciate. It is not without reason that such services as Twitter, Basecamp or AirBnB have been created in this language.

Ruby is ideally suited for the development of web applications. Its advantage is that it provides many libraries and high quality frameworks that improve the developer’s comfort. The process of building a web application is relatively faster in Ruby than in PHP. The first functionalities of the application can be obtained in a relatively low time. The most commonly used is the Ruby on Rails framework, which has gained great popularity with programmers.

Therefore, if time is a matter of value for a client, Ruby will be a good choice for them due to its time efficiency. At the very same time, there is no fear of any quality lost as the applications created in Ruby on Rails are of high quality and performance. Ruby is appreciated by developers for its brevity and the ease of introducing corrections and upgrades. This helps a lot at the later stages of work.

Obviously, PHP also has its supporters. There are more programmers on the market that have competencies in this area. Ruby creates a bigger barrier for entry for novice developers. The market trend shows, however, that more and more beginners in programming are deciding to learn this language by seeing more possibilities in it. A similar relationship can be shown with the customers, who want to create a web application and turn to the software houses that specialize in Ruby.

Why Poland is full of qualified Ruby on Rails developers? :)

We have no doubt that Poland is currently one of the most attractive markets in the world, where you can find qualified Ruby on Rails developers. Cooperating with clients every day, we are looking at this trend with quite an interest.  Polish developers are praised not only for their knowledge of this framework, but also for high standards of cooperation.

More and more geeks of RoR

The IT market is struggling around the world with the problem of demand exceeding supply with qualified specialists. Experienced and effective developers are constantly sought after. However in Poland there are quite a lot of them. We have noticed that more and more people are deciding to learn Ruby and its popular Ruby on Rails framework as they see it as a great prospect of development. The exchange of knowledge also comes in handy. The Ruby on Rails geeks community is extensive and appears to be a huge asset of this framework. This comes as quite helpful for developers, primarily when they need to solve a problem.

In addition, the high competences of Polish Ruby programmers should be appreciated. They receive job offers from foreign companies a lot, but a really good situation on the Polish market makes them reluctant to go. In Poland, Ruby developers are truly appreciated. Companies guarantee high earnings and very good working conditions.

Quality

The quality of products created with Ruby on Rails by Polish developers is appreciated all over the world. It is said that RoR programmers in Poland are one of the most developed groups with very high competence and the reasons seem quite obvious. They can combine the capabilities of the Ruby language and the Ruby on Rails framework, creating products based on such features as efficiency, functionality, time efficiency, application width and security. We must also add that Ruby on Rails is probably the best language that allows you to create a product based on MVP (Minimum Value Product) in a very short time. This is a very common solution used by many companies that regularly check and verify the value of their product on the market.

Poland is a great place for outsourcing

Not only the high skills and a wide range of Ruby on Rails developers decide that Poland is perceived as a very good place to outsource. There are also many other benefits, such as cost savings, the ability to cooperate with a customer or ever-growing market. In particular, the first two factors are really crucial from the partner’s perspective. Not only that by creating a product in Ruby on Rails you can be sure of quality and speed, but also software houses in Poland offer very good prices – much lower than in other countries of Western Europe.

Finally, we would like to draw attention to yet another important element – communication. An effective team of developers must be able to communicate effectively with the client to understand their needs and, as a result, create a product that coincides with the expectations. In fact, this is not a simple process at all. That is why it is so important for a software house to have effective cooperation rules, which are best, if confirmed by the recommendations of previous clients.

That’s the Strategy! Strategy Design Pattern :)

While working on a project, it is crucial to remember that you do not want to reinvent the wheel. If a solution for a problem is proved to be effective, reusing it will save you tons of time and a few headaches. In case of system architecture dilemmas, we have developed some patterns to ease a design process.

What is a design pattern?

A design pattern is a conceptual model that helps you solve design problems in various contexts. It is like a reusable template you can apply to a structuring code. The thing is, design patterns are well-documented, well-proven and commonly known. In other words, use a proper design pattern and be sure that other design pattern insiders (aka your coworkers) will get the hang of your ideas smoothly.

Eager to learn? Here comes the Strategy Design Pattern.

The strategy design pattern:

– defines a family of algorithms,

– implements each of the algorithms as a separate entity,

– allows each of the algorithms to be used interchangeably in a given context.

Real life example? Authentication

In one of our apps we have implemented a few strategies for authenticating requests. We allow authentication with cookies, JWT tokens and API keys. Sounds like a family of algorithms to me.

Let’s have a look at a sample implementation.

We have our family of authentication algorithms divided into three separate classes. Each class defines the concrete behavior; it is where all the implementation details go:

module AuthenticationStrategies
  class CookiesAuthentication
    def self.authenticate_request(request)
      puts "I implement a cookie authentication algorithm"
    end
  end
class JWTAuthentication
    def self.authenticate_request(request)
      puts "I implement a jwt authentication algorithm"
    end
  end
class ApiKeyAuthentication
    def self.authenticate_request(request)
      puts "I implement an api key authentication algorithm"
    end
  end
end

Then, we have a context/client class:

class Authentication
  def self.authenticate(authentication_strategy, request)
    authentication_strategy.authenticate_request(request)
  end
end
request = "I pretend to be a request"
Authentication.authenticate(AuthenticationStrategies::CookiesAuthentication, request)
Authentication.authenticate(AuthenticationStrategies::JWTAuthentication, request)
Authentication.authenticate(AuthenticationStrategies::ApiKeyAuthentication, request)

The above script outputs:

I implement a cookie authentication algorithm I implement a jwt authentication algorithm I implement an api key authentication algorithm

Summing it up

– design patterns are useful tools for solving architectural problems,

– knowledge of design patterns improves communication on system architecture with other developers,

– the Strategy Design Pattern suits your needs if you have a bunch of algorithms that can be used interchangeably in a given context.

Ruby Domain Specific Language :)

By reading this article you will learn what the DSL is and what it has in common with Ruby.

DSL, say welcome!

Referring to definition, DSL (Domain Specific Language) is a computer language specialized to a particular application domain. This means it is developed to satisfy specific needs. There are two types of DSL:

– An external DSL which requires its own syntax parser. A good known example may be the SQL language – it allows to interact with database in a language in which the database was not created.

– An internal DSL which itself does not have its own syntax but instead uses a syntax of a given programming language.

As you can probably guess we are going to stay focused on the second DSL type.

What does it do?

Basically, by making use of a Ruby metaprogramming, it allows to create your own mini-language. Metaprogramming is a programming technique that allows to write a code dynamically at runtime (on the fly). You may be unaware of this, but you probably use many different DSLs every day. To understand what a DSL can do, let’s take a look at a few examples below – all of these have one common element, but can you point it?

Rails routing

Rails.application.routes.draw do
  root to: 'home#index'

  resources :users do
    get :search, on: :collection
  end
end

Every person who have ever used Rails know a config/routes.rb file where we define application routes (mapping between HTTP verbs and URLs to controller actions). But have you ever wondered how does it work? In fact, it is just Ruby code.

Factory Bot

FactoryBot.define do
  factory :user do
    company
    sequence(:email) { |i| "user_#{i}@test.com" }
    sequence(:first_name) { |i| "User #{i}" }
    last_name 'Test'
    role 'manager'
  end
end

Writing tests often requires fabricating objects. Hence to avoid a waste of time, it would be a really good idea to simplify the process as much as possible. That is what the FactoryBot does – easy to remember keywords and a way of describing an object.

Sinatra

require 'sinatra/base'
 
class WebApplication < Sinatra::Base
  get '/' do
    'Hello world'
  end
end

Sinatra is a framework which allows you to create web applications from scratch. Could it be easier to define request method, path and response?

Other DSL examples might be Rake, RSpec or Active Record. The key element of each DSL is the use of blocks.

Building time

Time to understand what is hiding under the hood and how the implementation can look like.

Let’s assume we have an application which stores data about different products. We want to extend it by giving possibility to import data from a user defined file. Also, the file should allow to calculate values dynamically if needed. To achieve that, we decide to create DSL.

A simple product representation may have following attributes (product.rb):

class Product
  attr_accessor :name, :description, :price
end

Instead of using a real database we will just simulate its work (fake_products_database.rb):

class FakeProductsDatabase
  def self.store(product)
    puts [product.name, product.description, product.price].join(' - ')
  end
end

Now, we will create a class that will be responsible for reading and handling file containing products data (dsl/data_importer.rb):

module Dsl
  class DataImporter
    module Syntax
      def add_product(&block)
        FakeProductsDatabase.store product(&block)
      end

      private

      def product(&block)
        ProductBuilder.new.tap { |b| b.instance_eval(&block) }.product
      end
    end

    include Syntax

    def self.import_data(file_path)
      new.instance_eval File.read(file_path)
    end
  end
end

The class has a method named import_data which expects a file path as an argument. The file is being read and the result is passed to the instance_eval method which is called on the class instance. What does it do? It evaluates the string as a Ruby code within the instance context. This means self will be the instance of DataImporter class. Thanks to the fact we are able to define desired syntax/keywords (for a better readability the syntax is defined as a module). When the add_product method is called the block given for the method is evaluated by ProductBuilder instance which builds Product instance. ProductBuilder class is described below (dsl/product_builder.rb):

module Dsl
  class ProductBuilder
    ATTRIBUTES = %i[name description price].freeze

    attr_reader :product

    def initialize
      @product = Product.new
    end

    ATTRIBUTES.each do |attribute|
      define_method(attribute) do |arg = nil, &block|
        value = block.is_a?(Proc) ? block.call : arg
        product.public_send("#{attribute}=", value)
      end
    end
  end
end

The class defines syntax allowed within add_product block. With a bit of metaprogramming it adds methods which assign values to product attributes. These methods also support passing a block instead of a direct value, so a value can be calculated at runtime. Using attribute reader, we are able to obtain a built product at the end.

Now, let’s add the import script (import_job.rb):

require_relative 'dsl/data_importer'
require_relative 'dsl/product_builder'
require_relative 'fake_products_database'
require_relative 'product'

Dsl::DataImporter.import_data(ARGV[0])

And finally – using our DSL – a file with products data (dataset.rb):

add_product do
  name 'Charger'
  description 'Life saving'
  price 19.99
end

add_product do
  name 'Car wreck'
  description { "Wrecked at #{Time.now.strftime('%F %T')}" }
  price 0.01
end

add_product do
  name 'Lockpick'
  description 'Doors shall not close'
  price 7.50
end

To import the data we just need to execute one command:

ruby import_job.rb dataset.rb

And the result is..

Charger - Life saving - 19.99
Car wreck - Wrecked at 2018-12-09 09:47:42 - 0.01
Lockpick - Doors shall not close - 7.5

..success!

Conclusion

By looking at the all examples above, it is not hard to notice the possibilities offered by DSL. DSL allows to simplify some routine operations by hiding all required logic behind and exposing to user only the most important keywords. It allows you to get a higher level of abstraction and offers flexible use possibilities (what is especially valuable in terms of reusability). On the other hand, adding DSL to your project should be always well considered – an implementation using metaprogramming is definitely much harder to understand and maintain. Moreover, it requires solid tests suite due to its dynamism. Documenting DSL furthers its easier understanding, so it is definitely worth doing. Although implementing your own DSL can be rewarding, it is good to remember that it must pay off.

Did you get interested in the topic? If so let us know – we will tell you about DSL which we have recently created to meet the requirements in one of our projects.

What should you know about Ruby on Rails? :)

Ruby on Rails (RoR) is the most popular framework of the Ruby’s programming language. It is mostly used to create web applications. The fact that applications such as Twitter, Basecamp and Groupon have been created on its basis were already written here. In this article, we will try to bring its most characteristic features closer.

Specifics

RoR is an open source framework based on databases according to the MVC (Model-View- Controller) pattern. Developers, who use it on an everyday basis praise its simplicity. In fact, the database and the web server are more than enough to run an application. Thanks to the DRY (Don’t Repeat Yourself) rule, developers avoid repeating the same work at various stages of an application development and thus significantly accelerate their work. One shouldn’t forget another important method – Convention over Configuration. It assumes that the necessary configuration will be minimized by replacing it with ready-made models.

In addition, you need to return the ease of an application development. Thanks to the appropriate plugins, it can be extended very quickly with any additional functionalities. The great advantage of applications created in Ruby on Rails is also the fact that they are very efficient and safe.

Short way to MVP

Many companies decide to implement their product on the market, which is based on MVP (Minimum Value Product). It is a popular and effective method of checking the product’s potential on the market and improving it later in case it is needed. In this process, RoR is perfectly located. This framework allows very fast creation of a basic product containing the most important functionalities that a customer can verify on the market. In this way you can save time and thanks to good cooperation with developers, you can modify the product without any problems.

Recommendations

In the developers’ environment, that use Ruby on Rails on a daily basis, the framework is considered to be designed for the development of web applications. It is used by the largest brands, but also smaller companies that rely on e-commerce sales, create online communities or manage different content. From the point of view of a customer who is interested in creating a product, the credibility of specific software is very important. In the case of RoR, this is a factor determining its popularity. The success of Twitter or Basecamp would not be possible without the reliability and comprehensiveness of the created software.

WHAT IS THE FUTURE OF RUBY? :)

Although such languages as Java, Python or C ++ are still keep the leading positions among programmers, Ruby is growing very dynamically and is gaining new supporters. In 2018 it has got in the top ten of the most popular programming languages in the world.

One of the youngest languages

Ruby is well known in the developer’s community, but relatively less by those who do not have any contact with programming on a daily basis. The reason is that Ruby is one of the youngest languages. Despite this, it is estimated to be actively used by more than 10% of the programmers around the world. One cannot deny the impression that its popularity is constantly growing. In 2018, Ruby has been included to the group of the highest-paid programming languages.

Effective and functional

Ruby owes its publicity to such brands as Twitter, Basecamp, Shopify and Github. It is thanks to this language and its well-known Ruby on Rails framework that these applications were created. This is an example confirming its effectiveness. In the development environment, the language is appreciated for flexibility and a relatively low entry threshold. This means that a novice developer can quickly acquire skills that will allow to create the first products. An additional advantage is the fact that it is generally available (free), and is used in all operating systems – Windows, Linux, or Mac OS X.

Ruby is often used to create web applications that have been noticeably in demand over the recent years. Thanks to the Ruby on Rails framework, you can make a product on the basis of MVP (Minimum Value Product) in a relatively short time. It is about building a product with basic functionalities that allow the customer to verify its market potential. In this way, Ruby opens up the possibility of creating practical functionalities and works well in the implementation of more complex projects.

Our predictions

Currently, there are more than 50,000 vacancies in Polish IT market and this problem affects up to 2 million vacant jobs around the world. Therefore, one should expect further development of the IT industry, and with it – programming languages. Ruby should do well in the competition as it is supported by high quality and effectiveness of implemented projects.

In turn, new developers will appear on the employee market, whose skills will be highly rewarded. Of course, it’s hard to expect that Ruby would be able to become more popular than Java or Python in a short period of time, but we must emphasize the clear upward trend in Ruby. In addition, customer satisfaction works for its benefit and this seems to be the best advertisement.

 

BIG BRANDS CREATE WEB APPS IN RUBY ON RAILS :)

More and more the Ruby on Rails framework is being used by the largest brands to create their web applications. Thanks to the automation of many activities, it facilitates the work of developers, who can create a completed product in a short time. Many web applications have already been created in Ruby on Rails and we are presenting some of the most popular ones.

Twitter

The Twitter social network service is the Ruby on Rails’ largest showcase. Its founder, Jack Dorsey, decided to turn to this framework, as it could quickly create a functional product. He argued his choice by saying that the programmers found Ruby on Rails pretty handy to work with. In addition, during the work, the resulting service could be easily supplemented with any additional functionalities. Therefore, Dorsey emphasized the many advantages of the Ruby language, which you can also read about here.

AirBnB

Another service that has been a huge success. Created in the USA, it is used to book apartments and flats. To prepare the portal, e-mail templates, payment system and many other functionalities the Ruby on Rail framework was used.

Groupon

It was founded in 2008 in Chicago. The portal is used to purchase local services, travel and products. In this case, Ruby on Rails proved to be a great solution for a quick creation of a functional application that can be easily developed.

Github

Website designed for programming projects with enjoying great popularity. It was created in 2008 with the Ruby on Rails framework and the Erlang language. In 2018, Github has been taken over by Microsoft.

Basecamp

This tool enables a simple and remote project management. Its biggest advantage is the ability to manage multiple projects from one administration panel. It works great in running smaller businesses, but is also popular among managers dealing with complex projects.

Slideshare

Slideshare is a place on the web, where you can share multimedia presentations, documents, graphics and video. Launched as a LinkedIn website tool, it has gained a very high popularity among users. Slideshare supports, among others, marketing activities of companies. It was launched in 2006 and was created on the basis of the Ruby on Rails framework.

 

WHY IS THE RUBY PROGRAMMING LANGUAGE A GOOD CHOICE? :)

The Ruby Programming language along with its most popular Ruby on Rails framework have recently gained popularity. More and more developers around the world are choosing this language to work with due to its effectiveness and level of customers’ satisfaction.Ruby was created on the basis of the other programming languages such as Perl, Eiffel and Smalltak. The goal was to extract all the best features and combine them into a single whole. The perception of everything as an object, even primitive types, is the main characteristic of the language. In this regard, it definitely stands out from the other ones. In combination with the Ruby on Rails framework, Ruby Programming is a perfect tool to create web applications.Such applications as Twitter, Basecamp and Groupon have been created by means of Ruby on Rails. Basing on years of cooperation with the clients, experienced developers from Codest are willing to show a number of the Ruby language advantages.

1 Saving time

Hourglass on rocks

Using the newest programming tools both Ruby and Ruby on Rails affect the time efficiency of the implemented project. Whilst creating a web application, its first functionalities can be obtained much faster and with much less effort in comparison to other programming languages. Therefore, an application development progress, especially at the initial stage, is much larger.

2 Reliability

Blue chain

Ruby is a programming language that pays attention to quality. Developers write numerous tests, which means that the software has fewer errors. In this way you won’t have to waste time on any additional amendments. Thus you’ll be able to focus on the further software development.

3 Flexibility

Flexibility is another feature to be mentioned. Ruby does not limit a programmer giving them a possibility to modify or delete a code at any time. In case the client asks you to change a given functionality, the task can be achieved in a relatively short time. In addition to this, Ruby on Rails can instantly add the selected plugin and expand the application with new options.

4 Safety

In connection with the Ruby on Rails framework, Ruby provides mechanisms that affect application security – a built-in protection against XSS, CSRF and SQL Injection attacks, which are considered to be one of the most notorious attacks on web applications.

Smartphone on the desk

Conclusion

The Ruby Programming language along with its Ruby on Rails framework guarantees high quality of creating programs and web applications. The largest brands in the world develop their products using these tools as they provide high quality and reliability.