Slides from a talk I gave about using the Ruby on Rails console (and irb) to develop Web applications. Describes the features of the console, and how you might want to use it.
The full video from CppCon is available here: https://www.youtube.com/watch?v=PVYdHDm0q6Y
C++ provides a much richer set of abstractions than C. Classes, templates, overloading, and other core C++ features can be leveraged for more readable syntax, better compile time typechecking, more open ended genericity and improved modularity. On the flip side, C89 still boasts some advantages over C++, especially when viewed through a pragmatic lens. C ABIs on many platforms have been stable for decades, practically every language supports binding to C code through foreign function interfaces, and including nearly any C89 header has a negligible effect on compile time on modern computers.
The hourglass pattern provides the best of both worlds. By placing a headers-only C++ interface on top of a minimal C89 interface, it makes ABI issues a non-concern, and enables just a single binary to be shipped for a given platform. It makes providing bindings from other languages easier, and prevents ABI issues like incompatibilities between debug and release variants of runtimes.
This talk provides an overview of the pattern and teaches practical techniques for its implementation using C++14. Real shipping projects inspired the best practices described in the slides.
Code corresponding to this presentation can be found here: https://github.com/CppCon/CppCon2014/tree/master/Presentations/Hourglass%20Interfaces%20for%20C%2B%2B%20APIs%20-%20Stefanus%20Du%20Toit%20-%20CppCon%202014/code
At first glance, from a C# developer’s perspective, Ruby may seem a silly language with strange constructs and lousy syntax. But if you are able to get beyond this you will find a powerful and productive language to develop web applications and useful scripts. During the session we will take a look at Ruby from a C# perspective and analyse some of the “oddities” of this marvellous language!
For a demo to some colleagues, I created a Ruby on Rails demonstration. This presentation is used to show concepts, and illustrate the case. See http://changelos.com/2010/06/08/demoing-ruby-on-rails/ for the full story.
Geecon 2019 - Taming Code Quality in the Worst Language I Know: BashMichał Kordas
I don't know any other languages with more pitfalls, perils and gotchas than Bash. Still, we use it in almost every larger project for deployment or maintenance scripts, because there is no better, more powerful and more universal choice on Unix platform. However, there is ridiculous amount of things that could go wrong if you don't have deep understanding of shell scripting. Your experience about typical issues with Java or other JVM languages is definitely not enough here. You need to deeply understand Linux ecosystem and its history in order to write correct script... or you don't? I will prove to you that Bash could be tamed and made easy if proper code quality standards and static analysis tools are applied and enforced in your delivery pipelines. I'll share my opinions and experiences from a large banking project and I'll tell you which tools and style guides we use.
The full video from CppCon is available here: https://www.youtube.com/watch?v=PVYdHDm0q6Y
C++ provides a much richer set of abstractions than C. Classes, templates, overloading, and other core C++ features can be leveraged for more readable syntax, better compile time typechecking, more open ended genericity and improved modularity. On the flip side, C89 still boasts some advantages over C++, especially when viewed through a pragmatic lens. C ABIs on many platforms have been stable for decades, practically every language supports binding to C code through foreign function interfaces, and including nearly any C89 header has a negligible effect on compile time on modern computers.
The hourglass pattern provides the best of both worlds. By placing a headers-only C++ interface on top of a minimal C89 interface, it makes ABI issues a non-concern, and enables just a single binary to be shipped for a given platform. It makes providing bindings from other languages easier, and prevents ABI issues like incompatibilities between debug and release variants of runtimes.
This talk provides an overview of the pattern and teaches practical techniques for its implementation using C++14. Real shipping projects inspired the best practices described in the slides.
Code corresponding to this presentation can be found here: https://github.com/CppCon/CppCon2014/tree/master/Presentations/Hourglass%20Interfaces%20for%20C%2B%2B%20APIs%20-%20Stefanus%20Du%20Toit%20-%20CppCon%202014/code
At first glance, from a C# developer’s perspective, Ruby may seem a silly language with strange constructs and lousy syntax. But if you are able to get beyond this you will find a powerful and productive language to develop web applications and useful scripts. During the session we will take a look at Ruby from a C# perspective and analyse some of the “oddities” of this marvellous language!
For a demo to some colleagues, I created a Ruby on Rails demonstration. This presentation is used to show concepts, and illustrate the case. See http://changelos.com/2010/06/08/demoing-ruby-on-rails/ for the full story.
Geecon 2019 - Taming Code Quality in the Worst Language I Know: BashMichał Kordas
I don't know any other languages with more pitfalls, perils and gotchas than Bash. Still, we use it in almost every larger project for deployment or maintenance scripts, because there is no better, more powerful and more universal choice on Unix platform. However, there is ridiculous amount of things that could go wrong if you don't have deep understanding of shell scripting. Your experience about typical issues with Java or other JVM languages is definitely not enough here. You need to deeply understand Linux ecosystem and its history in order to write correct script... or you don't? I will prove to you that Bash could be tamed and made easy if proper code quality standards and static analysis tools are applied and enforced in your delivery pipelines. I'll share my opinions and experiences from a large banking project and I'll tell you which tools and style guides we use.
RubyConf Portugal 2014 - Why ruby must go!Gautam Rege
In this talk, I take the audience through ha whirlwind tour of Golang for Rubyists. I also discuss things like "Programmer Awareness", what can Rubyists learn from Go and how they can co-exist.
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
Author: Oleg Godovykh, eastbanctech.com
Kotlin is a new programming language built by Jetbrains and is a new member of JVM family. As opposed to typical reason to introduce some new language, Kotlin main goal isn't to create new paradigm or fill a new niche, but to make routine tasks much easier and safer. Kotlin gains popularity across Android developer community, and in this presentation it is shown how Kotlin usage can dramatically simplify typical mobile app development.
Slides containing information about my favorite features of the Ruby language. Many of these features exist in other languages, but in the context of my experience as a C, C++, and Java developer, offer a dramatic increase in expressiveness and productivity.
This slide show can also be used to teach a Ruby overview.
Why is big data all the rage? What is this "data science" that people are talking about? Why do I care — as a customer, and as someone who works at a company generating data? In this talk, I present the case for models, and how we can use data science to create and use models of our customers and the society around us.
PostgreSQL is a well-known relational database. But in the last few years, it has gained capabilities that previously belonged only to "NoSQL" databases. In this talk, I describe several of PostgreSQL that give it such capabilities.
In Python, operator overloading is accomplished via "magic methods" -- specially named methods that begin and end with double underscore ("dunder"). Most Python developers know about __init__ and even __str__, but magic methods are used to accomplish many things in the Python world. In this talk, I introduce a number of these methods, and show how they can be used to make our objects more expressive.
What can Ruby learn from Python (and vice versa)?Reuven Lerner
Ruby and Python are similar programming languages in many ways. But each has made different design decisions that affect how programmers in these languages think and work. In this talk, I contrast Ruby and Python, and some of the ways in which the languages differ.
Functional Python Webinar from October 22nd, 2014Reuven Lerner
Slides from my free functional Python webinar, given on October 22nd, 2014. Discussion included functional programming as a perspective, passing functions as data, and writing programs that take functions as parameters. Includes (at the end) a coupon for my new ebook, Practice Makes Python.
Since the beginning of software, we have bundled frequently-used functionality into libraries -- both our own, and those created by third parties. APIs tell software developers how to use a library, and make it possible for developers to treat libraries as black boxes, considering only what the library does, not how it does it.
Today, as software moves increasingly to the Web, APIs and libraries are also moving to the Web. This means that you can now outsource, by means of Web APIs, a huge amount of your application's functionality.
What does this mean for software developers? What does this mean for the future of software development? In this talk, I describe the past, present, and future of APIs, and how I believe the Web is changing the landscape.
Active Record 4.0 includes all sorts of exciting support for PostgreSQL! In this presentation, I show many of these improvements, and discuss why these are important for Web developers. If you haven't yet adopted PostgreSQL, now might be a great time and chance to do so.
Intro to cloud computing — MegaCOMM 2013, JerusalemReuven Lerner
What is cloud computing? This is an introduction that I gave at MegaCOMM 2013, a conference for technical writers in Jerusalem. The talk describes how the combination of Internet access, virtualization, and open source have made computing a utility that we can turn on and off at will -- similar in some ways to electricity, water, and other utilities with which we're familiar.
The latest version of my PostgreSQL introduction for IL-TechTalks, a free service to introduce the Israeli hi-tech community to new and interesting technologies. In this talk, I describe the history and licensing of PostgreSQL, its built-in capabilities, and some of the new things that were added in the 9.1 and 9.2 releases which make it an attractive option for many applications.
When you're writing a Ruby on Rails application, certain decisions seem appropriate and good at the beginning, but come back to bite you later on. In this talk, I list 20 different "traps," things that seem appealing, but which you should think twice before doing. The talk is based on my experience teaching Ruby and Rails classes to many people over the years, and was a presentation at the "Rails Israel 2012" conference held in Tel Aviv.
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...Reuven Lerner
My talk from the Megacomm 2012 conference in Jerusalem, on February 16th, 2012. I describe the fundamental underpinnings of the Web, how things have changed on both the browser and server sides, and what these technologies mean for users..
Git talk from Open 2011 conference in IsraelReuven Lerner
Git is an open source, distributed version control system that changes the way that you think about version control. In this lecture, I present some of the reasons why you would use a version-control system, and some of the compelling reasons why you should consider Git.
Dynamic languages, for software craftmanship groupReuven Lerner
Reuven Lerner's talk about dynamic programming languages in general, and about Ruby in particular. Why would you want to use a dynamic language? What can you do with one that isn't possible (or easy) with a static language?
Modern Web Technologies — Jerusalem Web Professionals, January 2011Reuven Lerner
What's the current state of Web technologies, and how does it affect professionals creating Web applications? In this talk, I survey the latest trends in Web technologies, and where I believe they're going in the near future.
An introductory, overview talk about PostgreSQL, given at the Database 2011 conference in January, in Israel. I point to a number of PostgreSQL features that make it a compelling choice in many different contexts.
Slides from a lecture I just gave on ActiveRecord 2.3. Describes configuration, methods, CRUD, finders, updating, associations, and a bunch of things that I wish I had known when I started with ActiveRecord.
Ruby is an object-oriented programming language; that much, everyone knows. But Ruby's objects work very differently from many other languages, especially if you're coming from a complied, statically typed language. In this lecture, I'll review the surprisingly simple rules that govern Ruby's objects. I discuss methods, classes, instances, and modules, and how these various pieces fit together into an integrated whole -- including such topics as inheritance, instance variables, class variables, mixins, and "include" vs. "extend".
Reuven Lerner's presentation from Open Ruby Day in Herzliya, Israel on June 27th, 2010. I covered a few tools that are not part of Rails, but which help you with deployment,
Reuven Lerner's first talk from Open Ruby Day, at Hi-Tech College in Herzliya, Israel, on June 27th 2010. An overview of what makes Rails a powerful framework for Web development -- what attracted Reuven to it, what are the components that most speak to him, and why others should consider Rails for their Web applications.
12. The Ruby way
Write in
Test IDE
fails?
Write a
test
Try in
console
13. The Ruby way
Write in
Test IDE
fails?
Write a Done? Try in
test browser
Try in
console
14. The Ruby way
It worked!
Write in
Test IDE
fails?
Write a Done? Try in
test browser
Try in
console
15. The Ruby way
Read logs,
backtrace
It worked!
Write in
Test IDE
fails?
Write a Done? Try in Failed? Try in
test browser console
Try in
console
Debugger
16. Whoa, that’s a lot!
• The idea is that the code is an extension of
your thoughts
• By “swimming through” and “playing with”
the code, you understand it better, and can
work with it faster
17.
18.
19. irb
• Interactive Ruby! (Comes with Ruby)
• Fire it up, and type Ruby code
• Define variables, classes, modules, methods
• All definitions disappear when you exit
• (Except for persistent storage, of course)
20. Why use irb?
• Test code
• Debug code
• Try things out
• Better understand Ruby
• Better understand an object or class
21. Rails requires more
• development/test/production environments
• ActiveRecord
• Other libraries, such as ActiveSupport
• HTTP requests and responses
• Model and controller objects
• Included gems
22. script/console
• Wrapper around irb
• Loads objects that are useful
• Makes other objects easily available
• Test your code, data, and assumptions
24. When?
• Always.
• It’s very rare for me to work on a Rails
project without a console open
• The console is where I test my objects,
experiment with code that’s longer than
one line, and try to debug my code
25. Simple IRB stuff
• Enter any Ruby code you want!
• Result of evaluation is displayed on the
screen
27. Printing vs. value
>> puts "hello"
hello
=> nil
>> ['foo', 'bar', 'baz'].each do |word|
?> puts word
>> end
foo
bar
baz
=> ["foo", "bar", "baz"]
28. Printing vs. value
>> puts "hello" This is what it prints
hello
=> nil
>> ['foo', 'bar', 'baz'].each do |word|
?> puts word
>> end
foo
bar
baz
=> ["foo", "bar", "baz"]
29. Printing vs. value
>> puts "hello" This is what it prints
hello
=> nil This is its value
>> ['foo', 'bar', 'baz'].each do |word|
?> puts word
>> end
foo
bar
baz
=> ["foo", "bar", "baz"]
30. Printing vs. value
>> puts "hello" This is what it prints
hello
=> nil This is its value
>> ['foo', 'bar', 'baz'].each do |word|
?> puts word
>> end
foo This is what it prints
bar
baz
=> ["foo", "bar", "baz"]
31. Printing vs. value
>> puts "hello" This is what it prints
hello
=> nil This is its value
>> ['foo', 'bar', 'baz'].each do |word|
?> puts word
>> end
foo This is what it prints
bar
baz
=> ["foo", "bar", "baz"]
This is its value
33. Multi-line irb
Open a class
irb(main):001:0> class Blah
irb(main):002:1> def sayit
irb(main):003:2> puts "hi"
irb(main):004:2> end
irb(main):005:1> end
=> nil
34. Multi-line irb
Open a class
irb(main):001:0> class Blah
irb(main):002:1> def sayit (Re)define a method
irb(main):003:2> puts "hi"
irb(main):004:2> end
irb(main):005:1> end
=> nil
35. Multi-line irb
Open a class
irb(main):001:0> class Blah
irb(main):002:1> def sayit (Re)define a method
irb(main):003:2> puts "hi"
irb(main):004:2> end
irb(main):005:1> end
=> nil Notice the prompt, showing line
numbers and block levels
36. Multi-line irb
Open a class
irb(main):001:0> class Blah
irb(main):002:1> def sayit (Re)define a method
irb(main):003:2> puts "hi"
irb(main):004:2> end
irb(main):005:1> end
=> nil Notice the prompt, showing line
Returns nil numbers and block levels
38. Variable assignment
• It works perfectly!
• Local, instance variables both work — but
instance variables don’t buy you anything
• Except namespace conflict avoidance
• Assignments disappear when irb exits
42. Inspecting objects
• Just type the object’s name
>> @bob
=> #<User:0x2645874
@new_record=true,
@attributes={"name"=>"Bob",
"job"=>"Test Dummy"}>
• notice instance variables and attributes
44. Classes, modules, and
methods
• You can define any or all of these
• Definitions work, and stick around for the
duration of the irb session
• Invisible to your running application
• When you exit, the definitions disappear
46. Defining classes
>> class Train
>> attr :passengers
>> def initialize
>> @passengers = [ ]
>> end
>> end Class definitions evaluate to nil
=> nil
>> t = Train.new
=> #<Train:0x102f391e0 @passengers=[]>
>> t.passengers << 'Reuven'
=> ["Reuven"]
>> t.passengers << 'Atara'
=> ["Reuven", "Atara"]
47. Define a new
ActiveRecord class
>> class Blah < ActiveRecord::Base
>> end
=> nil
>> Blah.first
ActiveRecord::StatementInvalid: RuntimeError: ERROR
C42P01 Mrelation "blahs" does not exist P15
Fparse_relation.c L857 RparserOpenTable:
SELECT * FROM "blahs" LIMIT 1
48. Define a new
ActiveRecord class
>> class Blah < ActiveRecord::Base
>> end
=> nil
Runtime message binding
>> Blah.first
ActiveRecord::StatementInvalid: RuntimeError: ERROR
C42P01 Mrelation "blahs" does not exist P15
Fparse_relation.c L857 RparserOpenTable:
SELECT * FROM "blahs" LIMIT 1
49. Avoiding huge output
• Person.all will return many records — and
thus print many records
• Assignment returns the assigned value
• Put a “;nil” after your command, and it’ll
evaluate to null, without any output!
•@people = Person.all; nil
50. Made a mistake?
• Use control-c to return to the top level
>> ['foo','bar','bat'].each do |word|
?> [1,2,3].each do |num|
?> ^C
>>
52. ActiveRecord
• ActiveRecord classes are available
• Console talks to the database for the
current environment
• Type the name of a class to see its fields
• Use class methods
• Create instances, use instance methods
55. Named scopes
• If you have a named scope:
named_scope :created_since, lambda
{ |since| { :conditions =>
['created_at >= ? ', since] }}
• Then it’s available as a class method, and we
can run it from inside of the console
>> Node.created_since('2010-9-1')
56. Huh? Named scopes?
• Don’t worry — we’ll get to those in an
upcoming session
• They’re really great, though!
58. Method differences
>> @p.save
=> false
>> @p.save!
ActiveRecord::RecordInvalid: Validation failed: First
name can't be blank, Last name can't be blank, Email
address can't be blank, Email address - Invalid email
address, Password can't be blank
60. Reloading
reload!
• Do this every time you change a model
• You will probably have to re-create instances
of ActiveRecord objects
• Otherwise, odd things can happen
61. Fat models =
easier testing
• ActiveRecord methods are immediately
available in the console
• This means that you can test your code
more easily when it’s in ActiveRecord
• Fat models win again!
• Remember: Keep your controllers skinny
62.
63. Sandbox
• script/console production --sandbox
• Reverts all changes that you made to the
database
• Allows you to work on your production
database without having to worry that
you’ll destroy things
64. Helpers
• Helpers: Methods for use within views
• Available under the “helper” object
• There are lots of helpers, and they have lots
of options. Test them before they’re in your
views!
71. Look at the response
>> app.get '/account/login'
=> 200
>> app.response.response_code
=> 200
>> app.response.body[0..100]
=> "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"n "http://www.w3.org/TR/
xhtml1"
>> app.response.has_flash?
=> false
72. ri
• Get documentation from within irb/console:
>> ri 'String#new'
>> ri 'String#length'
• Works really nicely, but it can take a long
time to execute
73. .irbrc
• Code is executed every time you run IRB
or console
• If a line causes trouble, it silently fails and
stops reading the file
• Yes, this is really dumb
• Great for loading files, configuration
settings
74. Naming .irbrc in Win32
• Name the file whatever you want
• Set the environment variable IRBRC to
point to that file
• Done!
75. IRB configuration
• IRB (and the console) is an essential tool
• There are many configuration parameters
and gems you can use to enhance it
• They’re great!
76. Configuration in Ruby!
• IRB.conf is a hash
• Set elements of this hash in .irbrc to change
the configuration
87. Summary
• Use the console!
• The more you use the console, the more
comfortable you’ll feel with Ruby
• It will save you lots of time and effort
88. Inspiration
• Amy Hoy’s “slash7” blog (http://slash7.com/
2006/12/21/secrets-of-the-rails-console-
ninjas/)
• “Err the blog” posting “IRB mix tape” (http://
errtheblog.com/posts/24-irb-mix-tape)
• StackOverflow posting on “favorite IRB
tricks” (http://stackoverflow.com/questions/
123494/whats-your-favourite-irb-trick)
89. Contacting me
• Call me in Israel: 054-496-8405
• Call me in the US: 847-230-9795
• E-mail me: reuven@lerner.co.il
• Interrupt me: reuvenlerner (Skype/AIM)