BASIC and Pascal have long become standard in the initial training of the programmer. For many, this is the first language from school or first-year university. However, over a decade the situation has not changed much. Are Basic and Pascal really suitable for learning
now ? Hasn’t anything better in a decade?
Think if there are reasons to use BASIC and Pascal besides historical ones?
At school, it has long been understood - it is better to give not programming, but the basics of using a computer. Maximum -
Logo in an environment like
KTurtle .
')
But for the first courses of the institute and the intensive study of schoolchildren, I think it is better to use Ruby and Python.
Of course, I do not insist on learning
only in Ruby. But, for example, a base to give 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:
- Outdated IDE. Of course, the console in TurboPascal is cool, but why not use more advanced and modern text editors? You can of course use Delphi or Visual Basic.Net, but these are professional tools with a bunch of unnecessary elements. They do not just have buttons Save and Run.
- Impracticality. BASIC and Pascal are now less and less used in production. Formally, 90% of professional programmers never use these languages ​​in practice.
- Complexity. Once they were really very simple programming languages. But progress does not stand still.
- Outdated API. In TurboPascal and QBasic, you cannot create window applications or make a simple website. Of course, this is not necessary for learning algorithms - but having a set of modern and “cool” tools, you can carry a student much more.
- 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 from the C ++ model. Needless to say, the outlook never interferes. Moreover, the C ++ approach is far from ideal and many tasks are much more convenient to solve in a different way. Of course, we are faced with the issue 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 :).
Improvements
What Ruby and Python do have these problems:
IDE
For Ruby and Python there is an interactive console - you enter a command and immediately see its result. Ideal area 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 install 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 interpretable programming languages ​​- so any text editor is suitable for working with them.
Industrial use
Giants like Google, Yahoo !, CERN or NASA are used industrially by Python. Ruby, by means of Ruby on Rails, actively and aggressively occupies a web platform.
I think it is not necessary to say that only with the knowledge of Ruby or Python you can already get a normal job, unlike Basic (the demand for Delphi-programmers is also falling).
In addition, in Ruby and Python, you can immediately tell OOP in earnest, without which it is difficult now.
Ease
Ruby and Python, due to the many paradigms underlying them, have many beautiful and simple solutions.
For example, cycles. In Pascal and Basic you need to think about
how to implement the desired cycle, in Ruby you specify
what you need to do:
loop do
# Endless cycle
end
count.times do | i |
# Loops count number of times
end
['a', 'b', 'c']. each do | i |
# Passes through each element of the array
end
And, for example, the mechanism of indentation in Python immediately learns to comply with the correct "herringbone."
The use
of higher-order functions (or delegate) allows you to make handling arrays easier and more understandable.
# Walk through the array and remove the 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’s easy to create
DSLs in Ruby (like mini-languages ​​for a specific task), you can hide many subtleties behind a beautiful API to teach consistently.
For example, this is the GUI definition of the
Shoes GUI in Ruby:
Shoes.app {
button ("Push me") do
alert "You click on button"
end
}
API
For Ruby, you can again mention
Shoes , since there you just have to make cool interfaces with graphics, effects, and animation. 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
}
Also, students will be able to write their own small site on Ruby on Rails or more simple
Sinatra .
I don’t even speak about standard APIs like access to a simple SQLite database.
Multi-paradigm
Learning Ruby or Python will correctly affect student development :). He can immediately show the approaches of many different schools in one language. Briefly introduced to higher order functions and lambdas 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, in contrast to QBasic and Borland Pascal. They eat Unicode support (so that children can enter their native language in the tests).
You can immediately teach how 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 Article of course more Ruby-oriented, but only because I know better its pros and cons.PPS In fact, Python and Ruby are not limited to this either. Languages ​​like Groovy or Lua are also great for learning tasks. It’s just that I didn’t work with them widely and I cannot answer for words :).see also
Hackety Hack is a tool for learning Ruby programming.