SlideShare une entreprise Scribd logo
1  sur  10
第3回
            初心者Scala


ひとりではじめる

 Scala


              2012/10/09
              @shitai246_
自己紹介
❖   シラトリタイスケ

    ๏ Twitter: @shitai246_

    ๏ Blog: http://a4p.me/

❖   エンジニア

    ๏ Java歴8年・Scala歴1年・JoJo歴18年

    ๏ Webサービスとかアドテクノロジーとか

❖   マネージャー

    ๏ 管理しないこともひとつの管理手法です

❖   ㈱ファンコミュニケーションズではエンジニアを募集しています

    ๏ 成果報酬型のアフィリエイト、A8.net/Moba8.netを開発・運用・保守するお仕事。

    ๏ Javaがメイン、ところによりPerl、稀にC。もれなくレガシー。Scalaは積極採用中。
ひとりではじめるScala
❖   仕事でScalaを使う上での障害

    ๏ 会社や上司の理解が得られない/説得できない

    ๏ Scalaを書ける同僚が少ない/居ない

    ๏ Scalaでコードを書いた経験が少なく、自信が持てない
どうする?
❖   ちょっとした処理をScalaで書いてみる

    ๏ 1回しかやらない

    ๏ 処理する量は多い(手作業でやるのはだるいor不可能)

    ๏ 他の言語(JavaとかPerlとか)だとめんどい

    ๏ コードにバグがあってもすぐわかるorトラブルに発展しない

    ๏ etc...



❖   メリット

    ๏ ひとりではじめられる

    ๏ 実際にScalaを使ってみて「Scala る」と周りに言える
Case1. 画像ファイルの縦横幅を取得する
❖   背景

    ๏ 数万くらいある画像ファイルの横幅・縦幅を取得する必要があった

    ๏ 画像ファイルは全てWebから取得可能、且つURLは全てデータ化できていた




❖   Scalaを使った理由

    ๏ 僕のスキルセット的にJavaかScalaかしか選択肢がなかった

    ๏ 既にJavaのコードを書くとイライラする病を発病していたためScalaで書いた
Case1. 画像ファイルの縦横幅を取得する
❖   実際に書いたコード

    ※ 大人の事情で多少変更しています。

     import javax.imageio.ImageIO
     import java.net.URL
     import scala.io.Source

     object Main {
       def main(args : Array[String]) : Unit = {
         val source = Source.fromFile(“/tmp/banner_url.txt”)
         val lines = source.getLines
         lines.foreach(getBannerSize)
       }
       def getBannerSize(url : String) : Unit = {
         try {
           val image = ImageIO.read(new URL(url))
           println(url + “,” + image.getWidth + “,” + image.getHeight)
         } catch {
           case e:Exception => Thread.sleep(100); getBannerSize(url)
         }
       }
     }
Case2. Xmlを解析する
❖   背景

    ๏ 8月にAmazonアソシエイトで特定カテゴリの商品の紹介料率が変わった

    ๏ 弊社でもAmazonアソシエイトと連携する部分があり、改修が必要になった

    ๏ 事前調査のため、APIから返却されるXmlのデータの一部を確認したかった

    ๏ APIの返却値がXMLで数百レコードもあり、手作業でやるのは不可能だった




❖   Scalaを使った理由

    ๏ ScalaはXmlがファーストクラスで扱えるため、やりたいことがシンプルに実現できた
Case2. Xmlを解析する
❖   実際に書いたコード

    import scala.io.Source
    import java.io.File
    import scala.xml.XML

    object Main {

        def main(args : Array[String]) : Unit = {
          val xml = XML.loadFile(new File(“./amazon/orders.xml”))
          val items = xml  “Item”
          val tag = items  “@Tag”

            tag.foreach(println)
        }
    }
やってみよう
❖   REPLでXmlを解析してみる

    scala> val xml =
       | <list>
       | <recode>
       |    <id>1</id><data value="data1" />
       | </recode>
       | <recode>
       |    <id>2</id><data value="data2" />
       | </recode>
       | <recode2>
       |    <id>3</id><data value="data3" />
       | </recode2>
       | </list>

    scala> println(xml  "recode"  "id")
    <id>1</id><id>2</id>

    scala> println(xml  "id")
    <id>1</id><id>2</id><id>3</id>

    scala> (xml  "@value").foreach(println)
    data1
    data2
    data3

    scala>
さいごに
❖   書いたコードは共有しよう

    ๏ みんなから見えるところにコードと実行結果を置くと興味を持つ人がいるかもしれない

    ๏ 僕の場合は Trac のチケットにコードをそのまま載せている

    ๏ 過剰な期待はしないこと




❖   どうしてもプロダクトコードをScalaで書きたい人は…

    ๏ ㈱ファンコミュニケーションズではエンジニアを募集しています

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Beginners Scala in FAN 20121023

  • 1. 第3回 初心者Scala ひとりではじめる Scala 2012/10/09 @shitai246_
  • 2. 自己紹介 ❖ シラトリタイスケ ๏ Twitter: @shitai246_ ๏ Blog: http://a4p.me/ ❖ エンジニア ๏ Java歴8年・Scala歴1年・JoJo歴18年 ๏ Webサービスとかアドテクノロジーとか ❖ マネージャー ๏ 管理しないこともひとつの管理手法です ❖ ㈱ファンコミュニケーションズではエンジニアを募集しています ๏ 成果報酬型のアフィリエイト、A8.net/Moba8.netを開発・運用・保守するお仕事。 ๏ Javaがメイン、ところによりPerl、稀にC。もれなくレガシー。Scalaは積極採用中。
  • 3. ひとりではじめるScala ❖ 仕事でScalaを使う上での障害 ๏ 会社や上司の理解が得られない/説得できない ๏ Scalaを書ける同僚が少ない/居ない ๏ Scalaでコードを書いた経験が少なく、自信が持てない
  • 4. どうする? ❖ ちょっとした処理をScalaで書いてみる ๏ 1回しかやらない ๏ 処理する量は多い(手作業でやるのはだるいor不可能) ๏ 他の言語(JavaとかPerlとか)だとめんどい ๏ コードにバグがあってもすぐわかるorトラブルに発展しない ๏ etc... ❖ メリット ๏ ひとりではじめられる ๏ 実際にScalaを使ってみて「Scala る」と周りに言える
  • 5. Case1. 画像ファイルの縦横幅を取得する ❖ 背景 ๏ 数万くらいある画像ファイルの横幅・縦幅を取得する必要があった ๏ 画像ファイルは全てWebから取得可能、且つURLは全てデータ化できていた ❖ Scalaを使った理由 ๏ 僕のスキルセット的にJavaかScalaかしか選択肢がなかった ๏ 既にJavaのコードを書くとイライラする病を発病していたためScalaで書いた
  • 6. Case1. 画像ファイルの縦横幅を取得する ❖ 実際に書いたコード ※ 大人の事情で多少変更しています。 import javax.imageio.ImageIO import java.net.URL import scala.io.Source object Main { def main(args : Array[String]) : Unit = { val source = Source.fromFile(“/tmp/banner_url.txt”) val lines = source.getLines lines.foreach(getBannerSize) } def getBannerSize(url : String) : Unit = { try { val image = ImageIO.read(new URL(url)) println(url + “,” + image.getWidth + “,” + image.getHeight) } catch { case e:Exception => Thread.sleep(100); getBannerSize(url) } } }
  • 7. Case2. Xmlを解析する ❖ 背景 ๏ 8月にAmazonアソシエイトで特定カテゴリの商品の紹介料率が変わった ๏ 弊社でもAmazonアソシエイトと連携する部分があり、改修が必要になった ๏ 事前調査のため、APIから返却されるXmlのデータの一部を確認したかった ๏ APIの返却値がXMLで数百レコードもあり、手作業でやるのは不可能だった ❖ Scalaを使った理由 ๏ ScalaはXmlがファーストクラスで扱えるため、やりたいことがシンプルに実現できた
  • 8. Case2. Xmlを解析する ❖ 実際に書いたコード import scala.io.Source import java.io.File import scala.xml.XML object Main { def main(args : Array[String]) : Unit = { val xml = XML.loadFile(new File(“./amazon/orders.xml”)) val items = xml “Item” val tag = items “@Tag” tag.foreach(println) } }
  • 9. やってみよう ❖ REPLでXmlを解析してみる scala> val xml = | <list> | <recode> | <id>1</id><data value="data1" /> | </recode> | <recode> | <id>2</id><data value="data2" /> | </recode> | <recode2> | <id>3</id><data value="data3" /> | </recode2> | </list> scala> println(xml "recode" "id") <id>1</id><id>2</id> scala> println(xml "id") <id>1</id><id>2</id><id>3</id> scala> (xml "@value").foreach(println) data1 data2 data3 scala>
  • 10. さいごに ❖ 書いたコードは共有しよう ๏ みんなから見えるところにコードと実行結果を置くと興味を持つ人がいるかもしれない ๏ 僕の場合は Trac のチケットにコードをそのまま載せている ๏ 過剰な期待はしないこと ❖ どうしてもプロダクトコードをScalaで書きたい人は… ๏ ㈱ファンコミュニケーションズではエンジニアを募集しています

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n