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

Class 10: Language Overview and Procedural Programming

Class 10: Language Overview and Procedural Programming

Notes for 7/18/2013

Ian Luke Kane

July 18, 2013
Tweet

More Decks by Ian Luke Kane

Other Decks in Technology

Transcript

  1. Programming  Languages Programming  languages  are  used  for  controlling  the  

    behavior  of  a  machine  (o6en  a  computer).   Like  natural  languages,  programming  languages  conform   to  rules  for  syntax  and  seman?cs. Objec?ve  C,  Ruby,  Python,  PHP,  C#,  Go,  Java,  C,  C++ Many,  many,  MANY  others.
  2. Where  do  I  Start?! • Code  Wars:  Ruby  vs  Python

     vs  PHP • Choosing  a  Programming  Language:  So  easy,  a   caveman  can  do  it • Programming  Language  Comparison • How  to  Pick  the  Right  Programming  Language • Choosing  a  Programming  Language • How  do  you  choose  to  use  a  specific  programming   language?
  3. How  Should  I  Proceed? Early  on,  I  would  say  it’s

     important  to  focus  on  some   “non-­‐func?onal  requirements.” A  requirement  that  specifies  criteria  that  can  be  used  to   judge  the  opera?on  of  a  system,  rather  than  specific   behaviors. Scalability,  Maintainability,  Reliability,  Availability,   Extensibility,  Performance,  Manageability,  Security
  4. Comparison  to  Human  Language Different  languages  are  capable  of  communica?ng

     ideas   differently. Mamihlapinatapei:  Yagan  (indigenous  language  of  Tierra  del   Fuego)  –  “the  wordless,  yet  meaningful  look  shared  by  two   people  who  both  desire  to  ini?ate  something  but  are  both   reluctant  to  start.” But  languages  share  many  commonali?es.  Same  goes   for  programming  languages.  E.g.  if  you  know  the   generali?es  of  noun/verb  interac?ons,  it’s  easier  to   learn  a  new  language.
  5. Procedural  Programming A  programming  paradigm  based  upon  the  concept  of

      the  procedure  call.   Procedures,  also  known  as  rou?nes,  subrou?nes,   methods,  or  func?ons  simply  contain  a  series  of   computa?onal  steps  to  be  carried  out. Any  given  procedure  might  be  called  at  any  point  during   a  program's  execu?on,  including  by  other  procedures  or   itself.  
  6. Procedural  Programming In  short,  procedural  programming  could  be  regarded  as

      a  list  of  instruc?ons  telling  a  computer,  step-­‐by-­‐step,   what  to  do  and  usually  having  a  linear  order  of   execu?on  from  the  first  statement  to  the  second  and  so   forth  with  occasional  loops  and  branches. Modularity  is  generally  desirable,  especially  in  large,   complicated  programs.  Inputs  are  usually  specified   syntac?cally  in  the  form  of  arguments  and  the  outputs   delivered  as  return  values.
  7. Procedural  Programming Modularity  is  a  so6ware  design  technique  that  

    emphasizes  separa?ng  the  func?onality  of  a  program   into  independent,  interchangeable  modules,  such  that   each  contains  everything  necessary  to  execute  only  one   aspect  of  the  desired  func?onality. Scoping  is  another  technique  that  helps  keep   procedures  strongly  modular.  It  prevents  the  procedure   from  accessing  the  variables  of  other  procedures  (and   vice-­‐versa),  including  previous  instances  of  itself,   without  explicit  authoriza?on.
  8. Procedural  Programming Design  Method  =  Top  Down.     This

     is  where  you  start  with  a  problem  (procedure)  and   then  systema?cally  break  the  problem  down  into  sub   problems  (sub  procedures).     This  is  called  func?onal  decomposi?on,  which  con?nues   un?l  a  sub  problem  is  straigh^orward  enough  to  be   solved  by  the  corresponding  sub  procedure.    
  9. Procedural  Programming  Issues The  difficul?es  with  this  type  of  programming,

     is  that   so6ware  maintenance  can  be  difficult  and  ?me   consuming.     When  changes  are  made  to  the  main  procedure  (top),   those  changes  can  cascade  to  the  sub  procedures  of   main,  and  the  sub-­‐sub  procedures  and  so  on,  where  the   change  may  impact  all  procedures  in  the  pyramid.
  10. SegSim  Explana<on “Segrega?on  Simula?on”:  A  simple  model  for  inves?ga?ng  how

      over  ?me  communi?es  can  become  segregated  based  on   various  prejudices.   1. Break  the  problem  down  into  one  dimension;  a  street   ini?ally  populated  with  equal  probability  either  black  ‘B’,   white  ‘W’  or  empty  ‘  ‘  houses.   2. We  then  allow  the  system  to  evolve  by  randomly  selec?ng   houses  and  applying  a  simple  condi?on:  If  the  house  is   surrounded  on  both  sides  by  a  house  different  to  itself,  it   will  decide  to  move  to  an  empty  loca?on  in  the  street  where   this  condi?on  is  not  sa?sfied.  In  the  unlikely  event  that  a   suitable  loca?on  cannot  be  found  a6er  a  designated   number  of  aeempts,  the  house  will  leave  the  street.
  11. SegSim  Sample  Output | BW W BWB BWBBWWBWWW W B

    BW BW WW BWW BWWW | : 17 | BW W BWB BWBBWWBWWW WBB BW BW WW WW BWWW | : 15 | BW W BWB BWBBWWBWWW WBB B BWWWW WW BWWW | : 13 | BBW W BWB BWBBWWBWWW WBB B WWWW WW BWWW | : 11 | BBW W BWBBBWBBWWBWWW WBB B WWWW WW WWW | : 8 | BBW BWBBBWBBWWBWWWWWBB B WWWW WW WWW | : 6 | BBW BWBBB BBWWBWWWWWBB B WWWW WW WWWW | : 5 | BBW WBBB BBWWBWWWWWBB BB WWWW WW WWWW | : 3 | BBWW BBB BBWWBWWWWWBB BB WWWW WW WWWW | : 1 | BBWW BBBB BBWW WWWWWBB BB WWWW WW WWWW | : 0
  12. SegSim  Modified  Rules Suppose  we  want  to  add  a  different

     type  of  house  that   plays  by  different  rules,  then  see  how  the  simulaGon   differs?   Consider  a  nomad  type  house  (label  ‘N’)    which  does  not   care  about  its  neighbors.  However,  it  remembers  how  long   it  has  been  in  one  locaGon,  and  if  longer  than  a  specified   threshold  it  moves  to  a  new  locaGon. How  must  we  modify  the  original  program  in  order  to   account  for  these  new  rules?