enterprise app dev in rails - the .net perspective
DESCRIPTION
Given at RubyConf2012 China, 11/18/2012TRANSCRIPT
运用 Rails 开发企业应用程序Enterprise App Dev in Rails- the .NET perspective
Eric Guo 过纯中
twitter.com/ecguo OR weibo.com/ecguo
Agenda
• Why Rails fits the Enterprise needs
• Rails Toolchain and Gems in Windows
• Typical Enterprise App – pl-form
• Scaffold custom
• Reporting in Excel
• Interoperation
• Deploy in Ubuntu and migrate to Linux
• 为何 Rails 是企业的良好选择
• Windows 下的 Rails 工具箱和 Gems
• 典型企业应用 – 电子表单
• 脚手架的定制
• 导出 Excel 报告
• 与现有系统的互操作性
• 部署到 Ubuntu ,逐步转移到 Linux
Enterprise vs Internet application – Same facts
Community
Trends
Development Speed
Operation
Inter-operation
Enterprise vs Internet application - Difference
• No special performance req
• Complex biz model rule
• Focus on IE or Firefox only
• Open half function for
current function
• Scalability
• Relative easy rule
• Cross-browser
• Close-loop function with full
automation
Before Rails, I already learned…
ASP.NET
Silverlight
Hibernate 3
Entity Framework
Telerik OpenAccess
WCF – Windows Communication
Foundation
PowerShell
I’m still a good citizen in Microsoft empire, but Web is future!
Three thing drive me switch to Rails
•ASP.NET MVC 3 vs Rails
•Cloud Foundry China Open
Tour 2012, Mark Lucovsky
•The Hackathon in May
2012, Shanghai, 60%
developer choose Rails
Rails adv and disadvantage in Enterprise View
• High density function/code ratio
• Full Stack Web Framework
• ORM, DB Migrate, Ajax, MVC model, template,
Testing framework, Caching, i18n.
• Function organized very well, Totally integrated.
• Good design pattern from .NET, Java, PHP, Perl
community, but no compatibility issue/debt in
design
• Open source
• Not as popular as Java and .NET
• Inter-operation
• Learning Gap
• Essential in HTML/CSS/JavaScript vs ASP.NET
• Command line vs Click GUI
• Toolchain problem in Windows
• Dynamic type vs Static type
• GFW (in china only)
Why Rails code have high density
self.part_request.part_request_details.each do |d|
status = 'Partial' if d.status != self.status
End self.part_request.save
Rails Code
• SELECT p.status INTO &PartRequestStatus FROM part_requests pWHERE p.id=&PartRequestID;
• SELECT d.status FROM part_request_details dWHERE d.part_request_id = &PartRequestID;
• UPDATE part_request_details d SET d.status='Partial'WHERE d.part_request_id = &PartRequestID; AND d.status <> &PartRequestStatus;
• COMMIT;
SQL Code (C# ADO.NET code not include yet…)
After ADO.NET code mixed with SQL…
It’s just one SQL statement, to get qty like previous SQL:
SELECT p.status INTO &PartRequestStatus FROM part_requests p
Some NOT correct fact about Rails
Windows is not friendly for RailsWindows is not friendly for RailsWindows is the easiest setup rails development platform if no issue happen.No source for ruby-1.9.3-p327 provided with debugger-ruby_core_source gem
Rails is magic and complex web frameworkRails is magic and complex web framework
Complex at beginning but flat learning curve after.
VIM, Git, Python, Linux, is pre-requestVIM, Git, Python, Linux, is pre-request
Mac is best environment for RailsMac is best environment for Rails
Focus the REAL value thing, “Getting Real”
Double cost hardware, no IE, Mountain Lion, Java story
Java and Apple
Java, Built In• “Write once, run anywhere” is true only if Java
is everywhere. With OS X, you know the Java Runtime is there for your applications, because it is built into the operating system. This means that when developing Java applications for deployment on OS X, you know that Java is already installed and configured to work with your customer’s Mac.
• Java is the only high-level framework on OS X besides Cocoa that provides a graphical toolkit for building applications.
https://developer.apple.com/library/mac/#documentation/Java/Conceptual/Java14Development/01-JavaOverview/JavaOverview.htmlMac OS X 10.6 Snow Leopard
Java Deprecation• As of the release of Java for OS X v10.6
Update 3, the Java runtime ported by Apple and that ships with OS X is deprecated. Developers should not rely on the Apple-supplied Java runtime being present in future versions of OS X.
• Apple deprecated Java and announced that applications using deprecated technologies such as Java won't be allowed in its official Mac Apps Store.
• Apple never promised the world to do no evil, but ... Oh well. It's clearly no angel.
• http://www.theregister.co.uk/2010/10/21/apple_threatens_to_kill_java_on_the_mac/
RubyMotion won’t success on iOS development.Web is the only correct way to development app.
Issue will also happen in Ubuntu with RVM
Stranger will not be friendly,
same thing if out of
recognition/knowledge in
Ruby on Rails
Try below if you using 1.9.3-
p327:
•gem install pry-debugger
•pry
Rails in Windows - Installation
• http://rubyinstaller.org/
• DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe
• https://github.com/oneclick/rubyinstaller/wiki/
Development-Kit
• C:\git>cd \devkit
• C:\DevKit>ruby dk.rb init
• C:\DevKit>ruby dk.rb install --force
• ansicon - Process ANSI escape sequences for
Windows console programs.
• Install Rubymine and Click Debug to install relative
debug gems
• gem upgrade –system
• gem upgrade
• gem install pry-debugger
• gem install bundle
• gem install ruby-oci8
• cd pl-form
• bundle install
Rails in Windows - Toolchain
• ActivePython 2.7
• Node.JS 0.8 or higher
• Sublime Text
• Git
• Firefox
• SSD
Req by Gems like pygments in Octopress
Req by Gems like ExecJS
Many plugin available for Rails
Git Extensions works great in Windows
Extension: SQLite, RESTClient with low memory
The typical bottleneck for rails eliminated
Rails in Windows - Gems
Some gems can NOT run in
windows: therubyracer
(replace with execjs)
gem install eventmachine –pre
gem install thin
more on:
http://ruby-china.org/wiki/win3
2-gem
The PaperLess-Forms Application
Eliminate all existing paper
based forms in Enterprise
• Not only save paper and
cost, but by human power
• Search quickly in form
directly.
• HTML5 for anydevice and
RESTful API for integration
User define forms instead of developer
A easy text format
DSL (Domain-Specific
Language)
• Header-Detail forms
supported
• Pre-defined Items
and Specs supported
User define forms in Text
Apply in Enterprise only
• Training better than
dummy design
• Text is better than GUI
• Code is better than
Configuration
• There is no advanced
user, only developer
PL-Forms features for Developer
• PL-Forms will generate forms
web page and underline support
program based on user define
forms
• Restful API available for every
forms after form generate
• Filled form data is in database table,
header, detail has two different
table, form field mapping to table
column, make writing SQL query
easy
• All source code and change history
available
PL-Forms more detail feature
• Typeahead auto complete
• Item and Spec as detail field
description
• Recent form quick list
• Define status code per each
forms (optional)
• input/update/delete action
will be record now, not only
including last one, all in
history
What happen after cmd: rails generator
C:\Ruby193\lib\ruby\gems\1.9.1\gems\railties-3.2.9\bin\rails;
Where is ‘hook_for’ lives?
http://rubydoc.info/gems/railties/Rails/Generators/Base.hook_for
Where are we, do we lost?
Read the Rails Guide!
And Stack Overflow…
And Rails Casts……
Author: Eric Guo <[email protected]>#mailto:[email protected] date: 5 months ago (Tue May 29 23:40:35 2012)Commit date: 5 months ago (Thu May 31 16:01:54 2012)Commit hash:864bc83859acbf07493b7cd39a134927c2925e2e
Introduce generate style programming for model and formsReview and change scaffold template
Contained in branches: master, rc8Contained in tags: oracle_production_run_here, oracle_run_here
Or just fork the code in Github
+----------------------+-------+-------+---------+---------+-----+-------+| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |+----------------------+-------+-------+---------+---------+-----+-------+| Controllers | 74 | 65 | 3 | 8 | 2 | 6 || Helpers | 39 | 35 | 0 | 4 | 0 | 6 || Models | 61 | 50 | 4 | 3 | 0 | 14 || Libraries | 104 | 77 | 0 | 7 | 0 | 9 || Integration tests | 0 | 0 | 0 | 0 | 0 | 0 || Functional tests | 8 | 7 | 1 | 0 | 0 | 0 || Unit tests | 11 | 6 | 2 | 0 | 0 | 0 |+----------------------+-------+-------+---------+---------+-----+-------+| Total | 297 | 240 | 10 | 22 | 2 | 8 |+----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 227 Test LOC: 13 Code to Test Ratio: 1:0.1
https://github.com/Eric-Guo/pl-form
Final after generated forms LOC
+----------------------+-------+-------+---------+---------+-----+-------+| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |+----------------------+-------+-------+---------+---------+-----+-------+| Controllers | 18459 | 13622 | 181 | 1254 | 6 | 8 || Helpers | 39 | 35 | 0 | 4 | 0 | 6 || Models | 1649 | 1458 | 205 | 137 | 0 | 8 || Libraries | 104 | 77 | 0 | 7 | 0 | 9 || Integration tests | 0 | 0 | 0 | 0 | 0 | 0 || Functional tests | 8 | 7 | 1 | 0 | 0 | 0 || Unit tests | 11 | 6 | 2 | 0 | 0 | 0 |+----------------------+-------+-------+---------+---------+-----+-------+| Total | 20270 | 15205 | 389 | 1402 | 3 | 8 |+----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 15192 Test LOC: 13 Code to Test Ratio: 1:0.0
https://github.com/Eric-Guo/pl-form
Excel can open many format
UTF8 CSV
UTF16 CSV
2003 XLS
2007 XLSX
CSV with BOM or no BOM
Rails can generate all of them
But correct only: CSV UTF8 with BOM
WebService, RestfulAPI, RabbitMQ, DB, FTP
Web Service RestfulAPI RabbitMQ Database FTP/SFTP
.NET Excellent Fair Good Fair Fair
Rails Poor Excellent Good On MVC only Fair
Time to thinking about migrate to Linux
Windows market share in Server OS Windows market share in Mobile OS
From http://news.netcraft.com/archives/2012/