Ruby / Python programming training

    BASIC and Pascal have long become the standard in the initial training of a programmer. For many, this is the first language from school or first year at a university. However, over a decade, the situation has not changed much. Are Basic and Pascal suitable for training now ? Isn’t anything better for a decade?

    Consider if there are reasons to use BASIC and Pascal other than historical?

    It has long been clear at school - it’s better not to give programming, but the basics of using a computer. Maximum - Logo in an environment such as KTurtle .

    But for the first courses of the institute and intensive study of schoolchildren, I think it is better to use Ruby and Python.

    Of course I do not insist on teaching onlyin Ruby. But, for example, giving a basis in Ruby, and more complex in Java / C # or C (including memory management), will more correctly affect the development of a programmer.

    Further arguments.

    Problems


    In the beginning, let's see if everything is so smooth with Pascal and BASIC:
    1. Deprecated IDE. Of course, the console in TurboPascal is cool, but why not use more advanced and modern text editors? You can certainly use Delphi or Visual Basic.Net, but these are professional tools with a bunch of extra elements. They do not just have Save and Run buttons.
    2. Impracticality. BASIC and Pascal are now less and less used in production. Formally, 90% of professional programmers never use these languages ​​in practice.
    3. Complexity. Once upon a time, they really were very simple programming languages. But progress does not stand still.
    4. Deprecated API. In TurboPascal and QBasic, you cannot create windowed applications or make a simple website. Of course, this is not necessary for learning algorithms - but after all, having a set of modern and “cool” tools you can enthrall the student much more.
    5. One paradigm. One of the problems of modern IT education is that students often do not know about the functional approach, and OOP is familiar only by the C ++ model. Needless to say, the horizons never interfere. Moreover, the C ++ approach is far from ideal and many tasks are much more convenient to solve in another way. Of course, we are faced with the question of chicken and eggs, since the C ++ approach is often used only because it is only taught. But it's time to get out of this vicious circle :).


    Enhancements


    What Ruby and Python cover these problems with:

    IDE

    There is an interactive console for Ruby and Python - you enter the command and immediately see its result. Ideal platform for experiments:
    >> 2 + 2
    => 4
    >> a = [1, 2, 3]
    => [1, 2, 3]
    >> a << 4
    => [1, 2, 3, 4]
    >> a.reject {| i | i% 2 == 0}
    => [1, 3]
    

    For Ruby, there is even an interactive console on the Web - you don’t even have to put anything on the training computer. This is especially true if the student wants to work out from home.

    And of course Ruby and Python are interpreted programming languages ​​- so any text editor is suitable for working with them.

    Industrial use

    Giants such as Google, Yahoo !, CERN or NASA are using Python industrially. Ruby, with the help of Ruby on Rails, is actively and aggressively occupying the web platform.

    I think it’s not necessary to say that only with knowledge of Ruby or Python can one get a normal job, unlike Basic (the demand for Delphi-programmers also falls).

    In addition, in Ruby and Python, you can immediately tell OOP in a serious way, without which it is now difficult.

    Ease

    Due to the many paradigms underlying them, Ruby and Python have many beautiful and simple solutions.

    For example cycles. In Pascal and Basic, you need to think about how to implement the desired loop; in Ruby, you indicate what you need to do:
    loop do
      # Endless cycle
    end
    count.times do | i |
      # Runs the count loop the number of times
    end
    ['a', 'b', 'c']. each do | i |
      # Iterates through each element of the array
    end
    

    And, for example, the indentation mechanism in Python immediately teaches you to observe the correct Christmas tree.

    The use of higher-order functions (or a delegate) allows you to make processing of arrays easier and more understandable.
    # Iterates through the array and removes elements for which true will be returned
    [1, 2, 3, 4] .reject do | i |
      i% 2 == 0 # Remove even numbers
    end
    # The result will be [1, 3]
    

    Since it is easy to create DSL in Ruby (as if mini-languages ​​for a specific task), you can hide many subtleties behind a beautiful API in order to teach sequentially.

    For example, the GUI definition in the Ruby Shoes library looks like this :
    Shoes.app {
      button ("Push me") do
        alert "You click on button"
      end
    }
    

    API

    For Ruby, you can mention Shoes again , as it’s easy to make “cool” interfaces with graphics, effects and animations. For example, the code draws a star and moves it behind the cursor:
    Shoes.app {
      @shape = star: points => 5
      motion do | left, top |
        @ shape.move left, top
      end
    }
    

    Students will also be able to write their own small site in Ruby on Rails or the simpler Sinatra .

    I'm not talking about standard APIs such as access to a simple SQLite database.

    Multiparadigm

    Studying Ruby or Python will correctly affect student development :). He immediately in one language can show the approaches of many different schools. A quick introduction to higher-order functions and lambda from functional programming languages. A look at OOP will not be closed only by the C ++ method, but will show the ease and possibilities of duck typing.

    Buns

    In addition, Ruby and Python are much more cross-platform. They are constantly being developed by the community, unlike QBasic and Borland Pascal. They have Unicode support (so that children can enter their native language in tests).

    You can immediately learn to write tests using a simple and beautiful RSpec:
    count.should == 10
    array.should include (item)
    


    And many more useful things that modern programming languages ​​have.

    PS The article is certainly more Ruby-oriented, but only because I know its pros and cons better.

    PPS In fact, Python and Ruby are not limited to this. Languages ​​like Groovy or Lua are also great for learning tasks. It’s just that I didn’t work widely with them and cannot answer for words :).

    see also


    Hackety Hack is a tool for learning Ruby programming.

    Also popular now: