fhwang.net

Coming to Ruby from Java

Ruby is a subtle language. If you come to it after mastering another language like Perl or Java, it's easy to write Ruby code that looks a lot like the code you used to write in your previous language. Now, writing code that way won't take any longer than it would've taken in your previous language. But if you decide to become another disciple in the burgeoning Ruby cult, you'll have a lot to gain by absorbing the various Ruby idioms. You'll write clearer code in less time, and you'll write less of it while accomplishing as much as you had before. I came to Ruby from Java, so here are a number of tips—some simple, some advanced—for the serious Java programmer who's starting to become a serious Ruby programmer.

One documentation note: When people are writing about Ruby, they use MyClass.method_name to refer to a class method, and MyClass#method_name to refer to an instance method. You never actually call MyClass#method_name in working Ruby code; it's just a documentation convention.

Naming and formatting

Underscores, not camel-case

In Ruby, class names are camel-case, but method and variable names are underscored instead. So instead of MyClass.doSomething, you have MyClass.do_something. I resisted this at first but these days I prefer it. I think it's slightly easier to read, and there are a lot of text editors and shells that can use the underscore character to know where individual words begin and end.

Boolean methods end with question mark

In Ruby, method names can end with a question mark, which Rubyists use to denote methods that return a boolean value. Use MyClass.valid? instead of MyClass.is_valid.

One-line methods

Classes in a highly factored OO design will often have lots of short methods that override those methods in parent classes, like:

def count
  @contents.split.size
end

But this can actually be laid out on one line, as long as the statements are separated by semicolons:

def count; @contents.split.size; end

This isn't really any less typing, but I personally prefer it because the visual size of the method is more in line with how complex the method is.

Multiple classes per file

Java idiom is to have a bunch of big classes with individual files: VoteCalculator.java, VoteRecord.java, VoteReport.java, etc. In Ruby it's much more common simply to put all those classes in the same file such as vote.rb. This cuts down on the amount of requiring you need to do, and I find that having all those classes together in the same place makes it easier for me to spot points of duplication that could use refactoring. Of course, if you're writing a lot of code, you shouldn't try to cram it all into one mega-file: My rule of thumb is to avoid letting files get longer than 750 lines, but that's just what works for me.

Hiding details

Use class methods to define pseudo-compile directives

Classes and class-level methods are a lot more dynamic in Ruby than in Java, so it allows you to do a lot more to tidy up your class level definitions. Here's an example: In my object-relational mapping library Lafcadio, a given domain class has fields corresponding to the given table in the database. Originally I had the domain class set those fields by overriding DomainObject.getClassFields:

class User < DomainObject
  def User.getClassFields
    fields = []
    fields << TextField.new(self, 'firstName') 
    fields << TextField.new(self, 'lastName') 
    fields << TextField.new(self, 'email') 
    fields << TextField.new(self, 'password') 
    fields << DateField.new(self, 'birthday') 
    fields 
  end
end

But in fact, you can save yourself a lot of noise by defining class level methods:

class User < DomainObject
  text 'firstName'
  text 'lastName'
  text 'email'
  text 'password'
  date 'birthday'
end

The line text 'firstName' is actually calling the method DomainObject.text. (Remember that class methods inherit like instance methods, which is why you can call a DomainObject class method inside of one of its children.) The actual methods are fairly complex for other reasons, but they could look something like this:

class DomainObject
  def DomainObject.date( field_name )
    add_field( DateField, field_name )
  end

  def DomainObject.text( field_name )
    add_field( TextField, field_name )
  end
end

If you're coming from Java, or indeed any language with a strong distinction between compile-time and runtime, this may be a little strange to look at. Remember that in Ruby, there is no compile-time: class and method definitions are invoked in the runtime like any other line of code. So although methods like DomainObject.text and DomainObject.date end up looking and feeling as if they were more like compile-time statements, all you're doing is dynamically changing the class—at the moment you're defining the class itself. And cleaning up your definition code quite a lot, to boot.

Avoid external utility classes

Let's say you're writing a Ruby app with lots of statistical methods, and you have to write a lot of those methods yourself. The Java-ish way to do this would be with a separate StatsUtil class, with only class methods:

class StatsUtil
  def mean( collection )
    total = 0.0
    collection.each { |i| total += i }
    total / collection.size
  end
end

But this is Ruby, and you can just add those methods to a pre-defined class:

class Array
  def mean
    total = 0.0
    each { |i| total += i }
    total / size
  end
end

… which automatically gives you less typing and more cohesion.

Now, if you've got a lot of different methods and would rather keep them somewhat separate, you can create a module and then include it:

module Stats
  def mean
    total = 0.0
    each { |i| total += i }
    total / size
  end
end

class Array; include Stats; end

You might be wondering about how to avoid name collisions, particularly since the Java community has such strict policies about not stepping into one another's namespaces. In my opinion this question isn't 100% resolved right now, but we don't need to solve it now because the Ruby community is still small. When we arrive at the promised land where Ruby is the next Perl, and there are 10,000 stable libraries floating around as Rubygems, we may have to resolve the namespace problem then. But I can say that for the last two years, I have used Ruby almost exclusively in my programming work, and this has never caused a problem for me. In practice, there aren't many cases where two different libraries will create methods with the same name on the same core class.

You probably don't need Factories.

In Java, you can't pick a class at runtime, which is why you might write Factories for complex apps. But in Ruby, not only can you pick a class at runtime, but you can find that class with nothing more than a string:

def init_class( class_name, *inst_args )
  a_class = Kernel.const_get( class_name )
  a_class.new( *inst_args )
end

require 'date'
date = init_class( 'Date', 2004, 11, 14 )

In fact, let's hide centralized utilities whenever possible.

There are times when you need global, centralized classes, but you don't necessarily have to make the user of your code aware of them. As in many other cases, method_missing is your friend here; you can use it to elegantly hide those central, theoretical classes behind the more concrete classes that you're actually more likely to interact with on a day-to-day basis.

Here's an extended example: Because I'm fanatical about testing, Lafcadio offers a functionality that allows you to swap out, at runtime, any global service that is related to an external resource, such as a database, SMTP, file system, etc. (One day this functionality will be pulled out into a small library so people can use it without including all of Lafcadio, but today is not that day.)

The ObjectStore is Lafcadio's centralized service which represents the database, and it uses that functionality so you don't have to write annoying SQL scripts in your test cases. The classes involved are:

  • Context: A singleton which tracks classes to instances. If an instance hasn't been created for a given service class, it creates an instance and saves it for future use.
  • ContextualService: The abstract class for any class whose instance should be tracked through Context.
  • ObjectStore: The concrete class which extends ContextualService.

Now, the most bare-bones way to get a service from the Context is to call

Context.instance.get_resource( 'ObjectStore' )

But nobody's going to remember that, so let's define Context#method_missing to allow us to call:

Context.instance.get_object_store

But why should you have to be reminded of the Context every time you want the ObjectStore? So we define ContextualService.method_missing to dispatch some calls to Context:

ContextualService.get_object_store

… which, since ObjectStore is a child of ContextualService, is the same as:

ObjectStore.get_object_store

That's a lot nicer, isn't it? Whoever's using the ObjectStore probably doesn't want to have to think about all that Context business. They just want to mess around with their domain objects and then move on.

Miscellaneous tips

Enumerable is your friend

This might be an obvious one, but I think some Java programmers, coming out of a language that makes dealing with collections so cumbersome, won't know to look for something nice like Enumerable. (Also, when I was learning Ruby I missed it since it's a module included in Array, meaning that its methods aren't visible when you're looking at the Array RDoc page.) In Enumerable, Ruby provides you with a rich API for manipulating collections. The above Stats.mean method gets shortened with a use of Enumerable.inject:

module Stats
  def mean; ( inject( 0.0 ) { |sum, n| sum + n } ) / size; end
end

No external configuration files

Why is it that Rubyists hate storing configuration information in external files, but Java programmers do it so much? Is it because Ruby is such an elegant language that it's an even quicker way to express settings than XML? Is it because Java programmers love writing tiny parsers for anything that might ever need to be configured? Is it because Ruby's design is a more faithful expression of the notion that code is data? Whatever the reason, we don't do it.

Typing is the enemy

Rubyists are always looking for ways to type less, and the best of us come up with beautifully elegant ways to do it. The favorite hack I took home from RubyConf 2004 was Rich Kilmer's suggestion of adding methods like Fixnum#days, Fixnum#hours, and Fixnum#minutes, so you can write code like 7.days + 8.hours and get a value expressing the time in seconds. If you manage to cultivate the same sort of impatience with keystrokes, you may end up coming up with similarly beautiful hacks and sharing them with the Ruby community. (Though you should be warned that cultivating that impatience may make your Java day job that much harder.)

If you're one of those rare souls who enjoys the craft of programming, and are about to spend more time in Ruby and less in Java, you've got a lot of great discoveries ahead of you. You'll find yourself writing code that feels more elegant and expressive—more free, even—and yet still powerful and robust enough to handle whatever work you throw at it. Hopefully the idioms described above will help you get deeper into the language. What are you waiting for? Get coding!

blog comments powered by Disqus

« Previous post

Next post »


Selected referrals to this page

Safari Tech Books Online - 0596523696 - Ruby Cookbook
First tracked March 8, 2007

… Ruby: Jim Weirich's "10 Things Every Java Programmer Should Know About Ruby" (http://onestepback.org/articles/10things/), Francis Hwang's blog entry "Coming to Ruby from Java" (http://fhwang.net/blog/40.html), and Chris Williams's collection of links, "From Java to Ruby (With Love)" (http://cwilliams.textdriven.com/pages/java_to_ruby) Despite the names, C++ programmers will also …

Java Great Big download - Wielki Katalog oprogramowania Open Surce dla srodowiska Java!
First tracked February 14, 2007

… (www.jsurfer.org)
Comic Bot (freshmeat.net)
Comic Collection (freshmeat.net)
ComicViewer (freshmeat.net)
Coming to Java from .Net (weblogs.java.net)
Coming to Ruby from Java (fhwang.net)
Command-Line Arguments (java.sun.com)
Command line options library 1.5.1 released (www.javalobby.org)
Commentary: Java needs a chief architect …

Gmane -- Mail To News And Back Again
First tracked January 31, 2007

… internet à la recherche d'info sur les divers erreurs à ne pas commettre quand on veux faire du beau Ruby et qu'on à les habitude du Java je suis tombé sur un article ( http://fhwang.net/blog/40.html) que j'ai trouvé assez interessant. J'ai de suite pris ma plus belle plume anglaise (bon en gros j'ai essayer de faire un baraguoin assez clair et simple) pour demander au monsieur …

Ruby for Perl Programmers
First tracked December 11, 2006

… http://www.rubyist.net/~slagell/ruby/
10 things every java programmer should know about ruby:
http://onestepback.org/articles/10things/
Coming to ruby from java:
http://fhwang.net/blog/40.html
Things I like:
-blocks
-you can be more expressive in ruby and essentially twist it into different domain-specific languages, see: http://blog.ianbicking.org/ruby-python-power.html …

Aprendiendo más sobre Rails y Ruby | agile-spain.com
First tracked December 9, 2006

… Java Programmer Should Know About Ruby por que es muy breve pero deja muy claras las diferencias de conceptos y da una idea de la potencia de Ruby. También leí otros artículos como este, este, este (parte 2, parte 3) o este, pero creo que es mejor pasar directamente a los dos primeros capítulos del libro Programming Ruby on Rails y aprovechar que está disponble gratuítamente …

(no title)
First tracked December 6, 2006


Things That Newcomers to Ruby Should Know [http://www.glue.umd.edu/~billtj/ruby.html]
Ruby QuickRef [http://www.zenspider.com/Languages/Ruby/QuickRef.html]
Francis Hwang: Coming to Ruby from Java [http://fhwang.net/blog/40.html]
Ruby programming language - Wikipedia, the free encyclopedia [http://en.wikipedia.org/wiki/Ruby_programming_language]
OSCON …

O'Reilly -- Safari Books Online - 0596523696 - Ruby Cookbook
First tracked December 4, 2006

…Jim Weirich's "10 Things Every Java Programmer Should Know About Ruby" (http://onestepback.org/articles/10things/), Francis Hwang's blog entry "Coming to Ruby from Java" (http://fhwang.net/blog/40.html), and Chris Williams's collection of links, "From Java to Ruby (With Love)" (http://cwilliams.textdriven.com/pages/java_to_ruby) Despite the names, C++ programmers will…

Simply Patrick: links for 2006-11-08
First tracked November 26, 2006

… interpreter (the official C implementation of the Ruby language) works internally.
(tags: ruby)
A Retrospective on PAIP
(tags: lisp programming)
Francis Hwang: Coming to Ruby from Java
Quote: "I came to Ruby from Java, so here are a number of tips—some simple, some advanced—for the serious Java programmer who's starting to become a serious Ruby …

Odds 'N' Ends Page
First tracked July 20, 2006

… Programmers Bookshelf
The Java(TM) Web Services Tutorial
RubyForge: Welcome
What is ruby?
JRuby Home
OSCON 2005 - 10 Things - Cover
Francis Hwang: Coming to Ruby from Java
ruby-doc.org
RDT - Ruby Development Tools: Welcome
Why's (Poignant) Guide to Ruby
Learning Ruby
Learn to Program, by Chris Pine - Ruby …

Ruby, Rails, Web2.0 » Blog Archive » Java and Ruby (on Rails)
First tracked April 18, 2006

… Know About Ruby If you plan to read just one document of this list, choose this one!
An Introduction to Ruby for Java Programmers Another nice introduction from Jim
Coming to Ruby from Java The name says all
Java - Ruby integration
JRuby - A 1.8.2 compatible Ruby interpreter written in 100% pure Java. Charles Oliver Nutter, one of the JRuby developers in …

Scripting languages
First tracked March 24, 2006

… http://www.rubyist.net/~slagell/ruby/
10 things every java programmer should know about ruby:
http://onestepback.org/articles/10things/
Coming to ruby from java:
http://fhwang.net/blog/40.html
Things I like:
-blocks
-you can be more expressive in ruby and essentially twist it into different domain-specific languages, see: http://blog.ianbicking.org/ruby-python-power.html …

Aprendiendo más sobre Rails y Ruby | agile-spain.com
First tracked March 22, 2006

… Java Programmer Should Know About Ruby por que es muy breve pero deja muy claras las diferencias de conceptos y da una idea de la potencia de Ruby. También leí otros artículos como este, este, este (parte 2, parte 3) o este, pero creo que es mejor pasar directamente a los dos primeros capítulos del libro Programming Ruby on Rails y aprovechar que está disponble gratuítamente …

Pandora - ComingToRubyFromJava » Introduction / ComingToRubyFromJava
First tracked March 13, 2006

… ComingToRubyFromJava » Introduction / ComingToRubyFromJava
Coming to Ruby from Java
Author: Francis Hwang
Converted to Pandora by: Julian I. Kamil
Original text: http://fhwang.net/blog/40.html
  Introduction
Ruby is a subtle language. If you come to it after mastering another language like Perl or Java, it’s easy to write Ruby code that looks …

RoR & Ruby styles - autoblogholog
First tracked March 12, 2006

… pour le plaisir d'apprendre un nouveau langage, un nouveau mode de développement web, et de nouvelles conventions (pour les switchers depuis java je vous conseille cette adresse)
pour en faire un métier
parce que cette liste est sans fin
Trackbacks
Aucun trackback.
Pour faire un trackback sur ce billet : http://pagesperso.laposte.net/ibi/tb.php?id=175 …

Ruby bookmarks - Play's Blog
First tracked January 17, 2006

… page
A Little Ruby, A Lot of Objects
Linux Journal - Ruby: Productive Programming Language
Ten Things a Java Programmer Should Know About Ruby
Francis Hwang - Coming to Ruby from Java
Ruby on Rails
Liens en Français :
Apprenez Ruby
RubyGarden - FrenchGroup
RubyFr.org
Liste de diffusion RubyFr.org
RubyFr.net …

Ruby's Cube: Java vers Ruby
First tracked December 22, 2005

… Apprendre Ruby (le langage de programmation) et Rails.
jeudi, décembre 22, 2005
Java vers Ruby
Un petit post avant de partir en vacances... Les erreurs à éviter quand on passe de Java à Ruby.
Il y a certains choses avec lesquelles je ne suis pas d'accord (ex: tout sur la même ligne séparé par des points-virgules, beurk, c'est pas lisible du tout!) …

Weblogs Forum - The departure of the hyper-enthusiasts
First tracked December 21, 2005

… http://www.rubyist.net/~slagell/ruby/
10 things every java programmer should know about ruby:
http://onestepback.org/articles/10things/
Coming to ruby from java:
http://fhwang.net/blog/40.html
Things I like:
-blocks
-you can be more expressive in ruby and essentially twist it into different domain-specific languages, see: http://blog.ianbicking.org/ruby-python-power.html …

DaTekStream
First tracked December 15, 2005

… Oskon`05 the 10 ruby things stuff does bring a lot to the eye. some of the real intresting ones
automatik patterns
dynamism beyond java
closure use kases
n some more here
posted by shodZ at 10:20 AM    | Comment
0 Comments:
Post a Comment
<< Home
Get awesome blog templates like this one from BlogSkins.com

learn ruby on rails on 43 Things
First tracked November 2, 2005

… tutorial on setting up a rails/mysql development environment on mac os x. if only all tutorials were this good.
here’s some good rails tutorials to help get ya started. and a good one for people coming from java.
Nov 01, 11:06PM PST | 1 comment
newguy
20 things
The meeting …  — 4 days ago
went very well. My boss was …

Pratik Dave - It Sure Beats Bookmarks
First tracked October 22, 2005

… 2005
April 2005
May 2005
June 2005
July 2005
August 2005
September 2005
October 2005
Friday, October 21, 2005
Francis Hwang: Coming to Ruby from Java
[4:49 PM-LINK]
Pretty self explanatory - as I come across stuff that's interesting that I'll want to refer to later, why not put it somewhere other than a file …

Just Looking: Luke Francl's Weblog
First tracked October 14, 2005

… Ruby on Rails thing. Cool, I think. What a great idea. Where's the Python version?
After a while, I just gave up. Ruby it is.
And in that vein, some links.
From Java to Ruby (With Love)
10 Things Every Java Programmer Should Know About Ruby
Coming to Ruby from Java
Posted at 17:07 Permanent Link
Luke Francl (look@recursion.org)

Late to the Party
First tracked October 7, 2005

… programmers feel every Java programmer should know in learning the language. The lazy, anti-introduction crowd should skip right to Item 10 and work their way up the list.
Coming to Ruby from Java
Using Ruby
Iteration, Blocks and Closures: Oh my.
One of the biggest differences between Java and Ruby are the language feature we call blocks (which are closures). …

Links: 20050924
First tracked October 7, 2005

… Delivers That Desktop Feel Most Users Expect
Or: The Author Is A Damn Fool. Or: I Hate "Serious" Email Users.
Setting up CIA with Rails and Subversion
Francis Hwang: Coming to Ruby from Java
If you come to it after mastering another language like Perl or Java, it's easy to write Ruby code that looks a lot like the code you used to write in your previous …

Collection & Copy - RubyについてJavaプログラマが知るべき10の事柄
First tracked September 8, 2005

… 大量のコードを書かない!
(0) Ruby はプログラムの楽しみを取り戻す
その他のリンク
Ruby Home Page
http://ruby-lang.org
Francis Hwang’s Blog
http://fhwang.net/blog/40.html
Bob Martin’s Blog
http://www.artima.com/weblogs/viewpost.jsp?thread=4639
ライセンス
この作品は、クリエイティブ・コモンズ・ライセンス(帰属 - 非営利 …

DigitalHobbit » Blog Archive » Ruby for Java Programmers
First tracked September 6, 2005

… Programmers
If you are a Java programmer and you’re interested in Ruby, you should read this presentation about 10 Things Every Java Programmer Should Know About Ruby.
This blog entry also has some nice Ruby information for Java developers.
About the most dangerous thing about Ruby is how more elegant and less verbose it is. And this is not only reflected …

Panasonic Youth » Blog Archive » Behold! A link-post!
First tracked August 29, 2005

… “sure looks like more the a fad…” (duh).
Ruby + Java + Spring = wiring java objects in ruby using dependecy injection. Is there a need for this, though?
Coming to Ruby from Java by Franci Hwang.
Cruise Control 2.3 is out
Sample chapter released from the upcoming Ajax in Action.
Google maps mania - unofficial blog for all gmaps extensions. …

Le blog » Archive du blog » Qu’est-ce qui rend le Ruby si balaise ?
First tracked August 12, 2005

… que les précédents tutoriaux que j’avais pu lire (sans ddoute parce qu’elle prend comme hypothèse, ce qui est vrai, que je connais le Java).
On peut aussi y ajouter ce post.
EDIT : damn, j’avais oublié le “=” dans le lien. Merci à Frederick d’avoir signalé la bévue.
Cet article a été publié le Friday …

Ruby from a Java guys POV
First tracked July 14, 2005

… about the Ruby language, but I will finish the Rails book (and the Programming Ruby) before voicing any potential complaints.
If you are a java guy like myself take a look at the blog entry on fhwang.net. He looks to have made the transition from java to ruby and addresses some of the issues that will make the trasintion easier.
tags: java, rails, ruby on rails

kkkkkkkk - Feedback on ”Ten Things a Java Programmer Should Know About Ruby”
First tracked June 11, 2005

… Things a Java Programmer Should Know About Ruby”
Java プログラマが知っておくべき Ruby についての 10 のこと
あとで読みます。
Francis Hwang:Coming to Ruby from Javaも。
[コメントを書く]
# 有狆 『せんせーっ筋トレ職人の実践講座の「お尻&ふとももの裏側」のページ、
ふとももの後ろ側の筋肉を鍛えることで、下半身を今より数倍大きくすることができます!! …

[Gridflow-dev] Re: ruby resources (fwd)
First tracked May 4, 2005

… http://www.postgresql.jp/interfaces/ruby/reference.html http://www.rubygarden.org/ruby?OneLiners http://www.erikveen.dds.nl/rubywebdialogs/index.html http://wxruby.rubyforge.org/wiki/wiki.pl http://fhwang.net/blog/40.html http://rrr.jin.gr.jp/doc/csv/ http://www.rickbradley.com/chron/20030625/ http://www.deveiate.org/code/IO-Reactor.html http://www.germane-software.com/software/rexml/ …

10 Things - More Resources
First tracked April 19, 2005


10 Things ... About Ruby
More Resources [ P rev | H o me | N ext ]
More Resources
Ruby Home Page
http://ruby-lang.org
Francis Hwang’s Blog
http://fhwang.net/blog/40.html
Bob Martin’s Blog
http://www.artima.com/weblogs/viewpost.jsp?thread=4639
Copyright 2005 by Jim Weirich (All Rights Reserved)

Kristian Kristensen’s Blog
First tracked April 19, 2005

… Search:
Links
ziaNET
Coming to Ruby from Java
Sunday April 17th 2005, 7:52 pm
Filed under: Ruby on Rails
Following a Ruby newsgroup led me to this blog post dealing with the small difficulties in going from Java to Ruby. It explains some of the idioms used in Ruby that are different than the common way of Java code writing.
Recommended! …

watch this &nbsp; » Blog Archive » Java Nightmare, Ruby Deliverance
First tracked February 2, 2005

… site that I worked on 3 years ago. They wouldn’t let me re-write it, just tack-on new features. Shudder .
Ruby made it all better. Come along, won’t you?
Coming to Ruby from Java
Ten Things a Java Programmer Should Know About Ruby
This entry was posted on Wednesday, February 2nd, 2005 at 9:47 am and is filed under General. You can follow any …

Matzにっき(2005-01-28)
First tracked January 31, 2005


Javaにはリファクタリングブラウザがあるが、Rubyにはない(RBBを紹介すべきか)。
Static TypeとDynamic Type
などの話題が爆発する。
Francis Hwangの「 Coming to Ruby from Java」も参考になる(かも)。
_ [OOP]OOP Is Much Better in Theory Than in Practice
「オブジェクト指向は一見すばらしいアイディアのように見えるけど実用上はそうでもない」という主張。

Comments for: First Post! - ja.zz
First tracked January 28, 2005

… First Post! @ January 28th 2005, 09:20 - Maarten Goldstein
back to overview
up
down
#1886
By: cameljoe [ Reply ]
doh.
http://fhwang.net/blog/40.html
Jan 28th, 2005 15:01:21
Sorta decent article on how to program in Ruby from a Java p...  :  cameljoe  (#1885)
#1885, doh. http://fhwang.net/blog/40.html …

Daniel Von Fange: The Ruby Way
First tracked November 15, 2004


Daniel Von Fange
Simple things matter most
« Pirates |Main
November 15, 2004
The Ruby Way.
Coming to Ruby from Java:
Ruby is a subtle language. If you come to it after mastering another language like Perl or Java, it's easy to write Ruby code that looks a lot like the code you used to write in your previous language. Now, writing code that way …