2003 Ruby Conference Introducing Ruby to the Corporate
2003 Ruby Conference Introducing Ruby to the Corporate World Jim D Freeze, Ph. D Cypress Semiconductor, Intl Saturday, 15 November 2003 Austin, TX 11/15/2003 1
Outline • Cypress • INSTITUTIONAL LEARNING 2003 Ruby Conference – Ruby Champion – Performance Results – Training – Abilities – Development Spec • INFRASTRUCTURE – Deployment Arch – Library Management • BEST PRACTICES – Test Bench – Project Directory structure – Application – Third Party Tools 11/15/2003 2
2003 Ruby Conference The Perfect Vacation 11/15/2003 3
2003 Ruby Conference The Perfect Job 11/15/2003 4
2003 Ruby Conference The Almost Perfect Job • Developing in Ruby at work and. . . • Not being forced to program in <fill in the blank> 11/15/2003 5
2003 Ruby Conference This Talk Is About • What We Did • What We Learned • Caveat – Every company and situation is unique 11/15/2003 6
2003 Ruby Conference EDA • Electronic Data Automation • EDA Companies using Ruby (That I know of) – Cypress – Agilent – Intel – AT&T – Maxim-IC – Motorola 11/15/2003 7
2003 Ruby Conference Cypress’ Use of Ruby • Completely Internal • Mostly work with text files • Most applications are Command Line driven – GUI’s are a luxury and do not add to the ‘A’ of EDA • Used for Developing and QA’ing Electrical Models • Used to generate Layout • Used to QA CAD flow 11/15/2003 8
2003 Ruby Conference INSTITUTIONAL LEARNING 11/15/2003 9
2003 Ruby Conference To be a Champion of Ruby at your company: • Your name doesn't have to be Dave, David, Lyle, Rich, Nathaniel, . . . • You don't have to write a book on Ruby • You don't have to teach a class on Ruby. . but it won't hurt. • You don't have to be a guru-answer guy on ruby-talk. . . I'm proof of that. • You do have to be honest • You should refrain from Value Judgments • You need to be couragous and take the initiative 11/15/2003 10
2003 Ruby Conference Empty Loop (Copy) Performance LOOP 1. PL open (in. File, "+<$in. File") || die; LOOP 1. RB File. open(out_file, "w") { |f| File. foreach(in_file) { |line| open (out. File, "+>$out. File") || die; f. print line } while (<in. File>) { } print out. File; } File Size: 261, 960 MB 11/15/2003 11
2003 Ruby Conference Non-Empty Loop Performance LOOP 1. PL do { $prev. Line=$cur. Line; $cur. Line = <in. File>; if ( $cur. Line && ($cur. Line =~ m/^s*+/ ) ) { chomp $prev. Line; $cur. Line =~ s/^s*+/ /; $cur. Line = $prev. Line. $cur. Line; } else { $prev. Line =~ s/[st]*[=][st]*/=/g; $prev. Line =~ s/s+/ /g; $prev. Line =~ s/^s+//; print out. File $prev. Line, "n"; } } while($cur. Line); LOOP 1. RB module Netlist def self. each_statement(file) buffer = "" File. open(file). each { |line| if ? + != line[0] yield buffer line. chomp! line. gsub!(/s*=s*/, "=") line. gsub!(/s{2, }/, " ") buffer = line else line. chomp! buffer << line[1. . -1] end } end File. open(out_file, "w") { |f| Netlist: : each_statement(file) { |s| f. puts s } } 11/15/2003 12
2003 Ruby Conference Non-Empty Loop Performance LOOP 1. RB require ‘netlistparser’ File. open(out_file, "w") { |f| Netlist: : each_statement(file) { |s| f. puts s } } 11/15/2003 13
2003 Ruby Conference Non-Empty Loop Performance LOOP 1. RB require ‘netlistparser’ File. open(out_file, "w") { |f| Netlist: : each_statement(file) { |s| f. puts s } } 11/15/2003 14
2003 Ruby Conference How Do I Promote Ruby? • Show Value – Perform an Honest Analysis (Comparison) – Don’t be defensive • Seek Educational Opportunities • Create an Infrastructure – Development Spec • Coding Guidelines • Corporate Library Architecture – Development Best Practices • Use Test: : Unit ! 11/15/2003 15
2003 Ruby Conference What’s the ROI? 11/15/2003 16
2003 Ruby Conference Ruby’s Abilities • Scalable • Re-usable • Maintainable 11/15/2003 17
2003 Ruby Conference Scalability • Development – Modular code • Object Oriented • Blocks, Closures, Iterators – Many or Few Developers – Small or Large Projects • Performance – Straightforward C/C++ Integration – Swig Support 11/15/2003 18
2003 Ruby Conference Maintainability Object Orientedness allows structured code Readable (low line noise) Easy to learn language Easy to read other peoples code POLS works for others, not just Matz Usage of Test: : Unit: : Test. Case provides examples and stable code 11/15/2003 19
2003 Ruby Conference Re-usability • OO Inheritance • Orthogonal functionality Mixed-in via Modules • Blocks and Iterators • Unit Tests 11/15/2003 20
2003 Ruby Conference Education 11/15/2003 21
2003 Ruby Conference Training • Seminar – 1 hr lecture or discussion • Long Course (University like) – 2 Days per week for one Qtr • Short Course (Tutorial) – 1 - 2 day training 11/15/2003 22
2003 Ruby Conference Training Tips • Steal – But Give Credit • Mix presentations with ‘live irb’ examples • Make presentations available online (Intranet) • Use work related examples • Use Exercises to break up the lesson • Give Homework Assignments for outside of class • Review code you have written for work 11/15/2003 23
2003 Ruby Conference Curriculum 1) Introduction 2) Control Structures 3) Strings and Printing 4) Test First Development 5) Regular Expressions, Case Statement 100% On Homework (code) 6) Iterators and Blocks 7) Files and Directories HW 2 HW 3 8) Inheritance 37. 5 100 9) Modules 10)Command Line Applications 11)Exceptions, Catch and Throw 12)Daemons, System Calls and Forking 13)Debugging, Profiling and Benchmarking 14)Threads and IO 15)Method Invocation, Method Missing, Module Methods and Eval 16)Ruby C 17)Swig 11/15/2003 24
2003 Ruby Conference Deployment 11/15/2003 25
2003 Ruby Conference Require Search Path Order 11/15/2003 26
2003 Ruby Conference Corporate site_ruby • Does not exactly mimic Ruby’s site_ruby – No 1. x directory – Shared Libraries are local to a project 11/15/2003 27
2003 Ruby Conference Library Bootstrapping • corp_init require ‘corp_init’ • Added to� Corporate Ruby Distribution – Adds Corporate site_ruby to $LOAD_PATH – require ‘corp_initialize’ • corp_initialize – Sets CORP_ARCH – Adds Groups to $LOAD_PATH 11/15/2003 28
2003 Ruby Conference Group Vaults Directory Hierarchy vault/ group 1/ bin/ lib/ project. rb project/ sun 4 v/ lnx 86/ libfile. rb group 2/ bin/ lib/ group 3/. . . 11/15/2003 Application require ‘company_init’ # Implicit Option require ‘’project’ # Explicit Option require ‘group 1/lib/project’ Libraries rel_require __FILE__, ‘project/libfile rel_require __FILE__, “project/#{CORP_ARCH}/sofile” 29
2003 Ruby Conference Library Requirements • Must be portable between corporate site_ruby and group vaults • Must be compatible with test bench • Must not require code change when deploying • Applications should not have to be aware of CORP_ARCH – No direct requiring of. so files • . so files are local to each project to support multi-OS and portablility 11/15/2003 30
2003 Ruby Conference BEST PRACTICES 11/15/2003 31
2003 Ruby Conference Directory Structure CHANGELOG INSTALL LICENSE Manifest README TODO bin/ contrib/ doc/ example/ ext/ <lang> lib/ setup. rb src/ test/ 11/15/2003 32
2003 Ruby Conference Typical Test Directory • • • • • drwxr-xr-x -r-xr-xr-x -r--r--r--r--r--r--r--r--r--r--r--r--r--r--r--r-xr-xr-x 11/15/2003 17 15 7 11 1 1 1 jdf jdf jdf jdf jdf 578 510 238 374 884 3062 8689 5576 710 1093 2908 4062 2715 3258 1562 533 398 Oct Sep Sep Sep Sep 9 14 25 23 16 14 25 25 9 9 13 25 25 25 13 14 9 08: 32 00: 43 16: 45 15: 32 08: 54 00: 41 16: 44 09: 50 23: 41 16: 44 23: 42 00: 41 09: 50 . / CVS/ data/ edit* tc_dbcellviewskill. rb tc_etestcp. rb tc_inputparser. rb tc_metalayout. rb tc_parallel_lines. rb tc_sblcellview. rb tc_sblfile. rb tc_sblobjects. rb tc_stdcbcm. rb tc_structmgr. rb test_all. rb* test_bin. rb* 33
2003 Ruby Conference Test Bench test_all A test_all B $: . unshift(". . /lib") tcs = %w{lib 1 lib 2} tcs. each { |lib| require lib } tcs. each { |lib| fork {require lib } } 11/15/2003 34
Application Boilerplate 2003 Ruby Conference #! /usr/local/bin/ruby -w # $Id$ require 'getoptlong' class App def initialize if 0 == ARGV. size STDERR. puts usage exit 0 end get_options rescue => err. . . end def get_options opts = Getopt. Long. new( [ "--action", "-a", Gettopt. Long: : REQUIRED_ARGUMENT]. . . end def main # add run code here end#App app = App. new. main 11/15/2003 35
2003 Ruby Conference Utilize Available Tools and Libraries • Webrick • CSV • YAML • webfetcher • ri • rdoc • strscan • Mini. Ruby. Wiki • ruwiki 11/15/2003 36
2003 Ruby Conference If All Else Fails % cat myprog. pl #!/usr/local/bin/ruby -w def usage <<-EOF Usage: #{File. basename($0). . . 11/15/2003 37
2003 Ruby Conference RUBY ADDS VALUE USE IT! 11/15/2003 38
- Slides: 38