Upgrade to Pro — share decks privately, control downloads, hide ads and more …

It's Not Ruby, But…

It's Not Ruby, But…

Ruby is a great programming language, but it’s not the only one. This week, we’ll be talking about different programming languages, what they’re good for, how they differ from Ruby, and why you might want to use them.

Bryce "BonzoESC" Kerley

March 19, 2018
Tweet

More Decks by Bryce "BonzoESC" Kerley

Other Decks in Programming

Transcript

  1. It's Not Ruby, But… • Polyglot Culture • Skills &

    Tools
 • Python • Elixir • Rust • Crystal
  2. Polyglot Culture • Some are fun and are good to

    learn and crib concepts and ideas from • Some are really useful for a specific task • Some are pretty good at lots of things
  3. Polyglot Culture • No one programming language is good at

    everything • When a language is the best at one thing it's frequently really bad outside that
  4. Contempt Culture • it's real bad • makes people feel

    bad about their valuable time spent learning "contemptible" languages
  5. Polyglot Culture vs. Contempt Culture • i've done php, java,

    and javascript professionally • and i enjoyed and learned from them all
  6. Polyglot Culture vs. Contempt Culture • it's okay to not

    like or avoid languages • but your reasons aren't everyone's reasons and your choices aren't everyone's choices
  7. It's Not Ruby, But… • Polyglot Culture • Skills &

    Tools
 • Python • Elixir • Rust • Crystal
  8. Skills • Getting a handle on a single programming language

    is a difficult proposition • Learning a second language is also hard • Being able to switch languages on the same project is even harder
  9. Skills • so gj everyone that can switch from ruby

    to js without forgetting: • parens around arguments • return statements • how prototypes work
  10. Skills • the more languages you learn, the easier it

    gets • especially if those languages are related somehow
  11. Tools • lots of stuff in ruby is available for

    other languages • package managers • syntax highlighting for your editor
  12. Tools • sometimes it's not great, depending on how fresh

    the language is • sometimes it's not great because the language just grew differently
  13. It's Not Ruby, But… • Polyglot Culture • Skills &

    Tools
 • Python • Elixir • Rust • Crystal
  14. import angr 
 import simuvex 
 import binaryninja 
 


    bv = binaryninja.BinaryViewType['ELF'].open('magic') 
 bv.update_analysis_and_wait() 
 
 sum_string = "sum is %ld\n" 
 strings = bv.get_strings() 
 sum_ref = [r for r in strings if 
 sum_string == bv.read(r.start, r.length)][0] 
 code_ref = bv.get_code_refs(sum_ref.start)[0] 
 main_start = bv.get_previous_function_start_before(code_ref.address) 
 main_func = bv.get_function_at(main_start) 
 main_return = [o for o in main_func.low_level_il.basic_blocks[0] if 
 binaryninja.enums.LowLevelILOperation.LLIL_RET == o.operation][0] 
 
 
 proj = angr.Project('magic', 
 load_options={'auto_load_libs': False}) 
 add_options={simuvex.o.BYPASS_UNSUPPORTED_SYSCALL} 
 path_group = proj.factory.path_group(threads=1) 
 path_group.explore(find=main_return.address) 
 
 print path_group.found[0].state.posix.dumps(0) 
 print path_group.found[0].state.posix.dumps(1)
  15. Why Python? • Libraries that aren't available in Ruby •

    Or aren't as good in Ruby • Documentation to do a thing that doesn't exist for Ruby
  16. Big Changes in Python • mandatory good indent style •

    without parens you get the function as a value instead of calling it • you need to return to return a value
  17. Big Changes in Python • global functions that call awkwardly-named

    methods instead of just methods • len(collection) or collection.__len__() • instead of collection.length()
  18. Big Changes in Python • Python package management developed parallel

    but independent from Ruby's • octopus eyes work a lot like human eyes but they evolved 'em completely differently
  19. Big Changes in Python • python 2 vs. python 3

    • use python 3 when you can
  20. Small Changes in Python • nil is None, true is

    True, false is False • it's already installed with a whole pile of libraries • a lot of Linux distros use it
  21. It's Not Ruby, But… • Polyglot Culture • Skills &

    Tools
 • Python • Elixir • Rust • Crystal
  22. Elixir • i already knew Ruby and Erlang so i

    picked up Elixir in a weekend
  23. It's Not Ruby, But… • Polyglot Culture • Skills &

    Tools
 • Python • Elixir • Rust • Crystal
  24. Rust • Mozilla made Rust because C++ doesn't do everything

    they need to • new by PL standards, first showed up in 2010
  25. Rust • you will hear people complain about the compiler

    being really picky • working as intended
  26. In most browsers, it would be hard to get this

    right. Parallelism is a known hard problem, and the CSS engine is very complex. It’s also sitting between the two other most complex parts of the rendering engine — the DOM and layout. So it would be easy to introduce a bug, and parallelism can result in bugs that are very hard to track down, called data races. […] With Rust, you can statically verify that you don’t have data races. This means you avoid tricky-to-debug bugs by just not letting them into your code in the first place. The compiler won’t let you do it. https:/ /hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/
  27. Rust Projects I've Done • sinatra-like webapps that call shell

    scripts • programs that get hacked but only the right way
  28. use std::net::UdpSocket; 
 
 fn main() { 
 let socket

    = UdpSocket::bind("0.0.0.0:1337"). 
 expect("failed to bind udp socket"); 
 
 socket. 
 set_read_timeout(None). 
 expect("couldn't set forever timeout"); 
 
 loop { 
 let mut buf: [u8; 32] = [0; 32]; 
 
 let (amt, src) = socket. 
 recv_from(&mut buf). 
 expect("failed to recv"); 
 
 assert!(amt == 32, "recvd {}, wanted 32", amt); 
 
 let expectation = [56, 55, 53, 53, 49, 99]; 
 
 if buf == expectation { 
 let reply ="nice!".as_bytes(); 
 
 socket. 
 send_to(reply, &src). 
 expect("failed to reply, rats"); 
 } 
 } 
 } 
 

  29. Twitter to Mastodon • Nintendo Switch posts screenshots and videos

    to twitter and facebook • I want those on my Mastodon account
  30. Twitter to Mastodon • watch my tweets for #NintendoSwitch on

    the twitter streaming API • pick the best media version to post to mastodon • download the media • upload it to mastodon • post the toot
  31. Twitter to Mastodon • honestly it'd be a ruby program

    • want to fit it in spare memory on an ec2 instance • and not think too hard about it
  32. switch-tweet-copier • got to the media picker before i got

    tied up in types and compiler errors • JSON's type system vs. Rust's type system
  33. It's Not Ruby, But… • Polyglot Culture • Skills &

    Tools
 • Python • Elixir • Rust • Crystal
  34. private def process_media(tweet) 
 blank = [] of ::Mastodon::Entities::Attachment 


    extended_entities = tweet.extended_entities 
 return blank if extended_entities.nil? 
 media = extended_entities.media 
 return blank if media.nil? 
 
 media.map do |medium| 
 pp medium.type 
 
 case medium.type 
 when "video" 
 process_video(medium) 
 when "photo" 
 process_photo(medium) 
 else 
 nil 
 end 
 end.compact 
 end 

  35. Crystal • I finished the project :3 • Only had

    to update a bunch of libraries "shards" by hands
  36. It's Not Ruby, But… • Polyglot Culture • Skills &

    Tools
 • Python • Elixir • Rust • Crystal
  37. Conclusions • learn more languages • don't hate • lots

    of good languages for different tasks