SlideShare ist ein Scribd-Unternehmen logo
1 von 64
Downloaden Sie, um offline zu lesen
Ať se z kódu nepráší!
            Juraj Michálek
     7 5. 2012 - FI MUNI - Brno
      .
    http:/ /georgik.sinusgear.com
    http:/ witter.com/sinusgear
          /t
Niečo o mne
Čo nás čaká
Testovanie v C


Kvalita kódu, open source a projekty


C vo svete Applu, Objective-C
Když se dívám na svůj kód,
tak se musím pochválit.
Nevypadá věru zle,
zkrátka program jak má být.


Před naší, za naší
ať se z kódu nepráší! Hej!
Háá! Chybáá!
Testovanie

žiadne
manuálne
automatické
Žiadne testovanie
Ľudová múdrosť


Bez testů do vývoje nelez!
Manuálne - black box
Spustíme a aplikácia ...
Manuálne - debugger




Když něco rozeberem, tak leda debuggerem
http://georgik.sinusgear.com/2010/09/19/zaznam-z-prednasky-kdyz-neco-rozeberem-tak-leda-debuggerem/
Prečo automatizovať?


Som vývojár alebo debuggrista?
Automatizované testy

 Záchranná sieť pre vývojárov
 Živá dokumentácia
 Lepší dizajn
 Viac času na vývoj
Typy testov

Unit testing - jednotkové testy
Integračné testy
Akceptačné testy
Regresné testy
Test Driven Devel.

Testy prvé


Potom kód
Unit Testing

izolácia
  setUp - príprava prostredia
  test - samotný test
  tearDown - upratanie prostredia
Príklad testu

int a=41;
a++;
assert( a == 42, “Universe should be ok”);
Minunit

Minimalist Unit Testing Framework for C


http://www.jera.com/techinfo/jtns/jtn002.html
Minunit - code

/* file: minunit.h */
#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
#define mu_run_test(test) do { char *message = test(); tests_run++; 
                               if (message) return message; } while (0)
extern int tests_run;
mu_runtest

mu_runtest( test_currency );


mu_runtest( test_accounting );
mu_assert


mu_assert(“Should not be null”, state == null);
Spustenie

gcc *.c -o test
./test
  ALL TEST PASSED
  Tests run: 2
gcc - c99
for (int i=0; i<42; i++)
  error: ‘for’ loop initial declaration
  used outside C99 mode


zmena normy parametrom:
  gcc -std=c99
Check framework
http://check.sourceforge.net/


Inštalácia
 ./configure
 make
 make install
Organizácia testov
Test Case
 testovaný prípad
Test Suite
 sada Test Case
Test Runner
Test Fixtures

void setup();


void teardown();
Kontrólne fcie

fail_if ( employee->age != 43, “Problem”);


fail_unless( employee->age == 43,
"Incorrect age.");
Kompilácia


gcc -lcheck test.c -o test
Spustenie testu
./test
Príklad:
  Running suite(s): Employee testing
  0%: Checks: 1, Failures: 1, Errors: 0
  main.c:45:F:Core tests:test_age:0:
  Incorrect age.
Ďalšie frameworky

C/C++
 CxxTest: http://cxxtest.com/
 Boost: http://boost.org
Continuous Integration




 Jenkins
 http://ci.sinusgear.com
Open source

Projekty


Licencie
Code_swarm
Organic soft ware visualization of
project repositories
http://code.google.com/p/codeswarm/
Gource




http://code.google.com/p/gource/
Ohloh.net

hodnotenie open source projektov
Lynda.com
Dobrý zdroj znalostí
se-radio.net
Kvalita kódu

Kód sa viackrát číta, než sa píše.


Review kódu
Ot vorenie kódu

GitHub.com
 Social Coding
 fork
Licencie
Free soft ware
 GNU/GPL, LGPL


Open source
 BSD, MIT, Apache
 business friendly
Čítajte licencie
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including without
limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to
whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
Čítajte licencie
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including without
limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to
whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

The Software shall be used for Good, not Evil.
Objective-C

programovací jazyk vychádzajúci z C


objektové princípy zo Smalltalku
Objective-C
1983 - Brad Cox a Tom Love
 zakladajú StepStone
1988 - Steve Jobs - NeXT
 licencuje Objective-C od StepStone
 rozširuje GCC, vyt vára AppKit
Objective-C

1996 - Apple ohlásil akvizíciu NeXT
 429 mil. $
Cocoa framework
Apple a C

Mac OS 10.7
 Xcode 4
 Command Line Tools for Xcode
   http://developer.apple.com
Xcode 4


Nutné: Mac OS X 10.7
Objective-C

Syntax: cammelCase


Prefix: NS (od NextStep)
Hello FI MUNI!




   Command + R
NSString

NSString *who = @”FI MUNI”;


NSLog(“Hello %@!”, who);
Boolean

BOOL isFIBest = YES;


BOOL isCBoring = NO;
Správa pamäte
Nové verzie Mac OS podporujú auto-
garbage collection.


Nespoliehajte sa na to!
 Naučte sa manažovať pamäť.
 Nefunguje na mobilných zariadeniach.
Retain Counter

alokácia - zvýšenie počítadla


dealokácia - zníženie počítadla
Pravidlá

Ak objekt vlastníš, musíš ho uvoľniť.


Ak objekt nevlastníč, nesmieč ho uvoľniť.
Vlastnenie objektu

alloc, new, retain, copy


Každý ANRC musí mať release!
Alokácia - new
Alokácia a inicializácia




       Preferovaný spôsob
Rozdelenie kódu

rozhranie (interface) - *.h


implementácia - *.m
Interface
@interface Employee : NSObject {
@private
  NSString *name;
  NSString *surname;
  NSDate *age;
}
@end
Implementácia
@implementation Employee

- (void) myMethod {
   NSLog(@"Hello");
}

@end
Znak pred metódou

- (void) myMethod


znak mínus - metóda inštancie
znak plus - statická metóda
Prístup k zdrojom
NSURL


NSURL *myURL = [NSURL
fileURLWithPath:path];


file:/ /Users/georgik/file.txt
      /
Prečo používať NSURL?
 Pretože to tak Apple povedal.


 rýchlejšie na iOS
 zachytenie chyby v prípade zlého
 formátu
 omnoho mocnejšie
Allegro


podpora aj pre iPhone
Ať se z kódu nepráší!
            Juraj Michálek
     7 5. 2012 - FI MUNI - Brno
      .
    http:/ /georgik.sinusgear.com
    http:/ witter.com/sinusgear
          /t

Weitere ähnliche Inhalte

Ähnlich wie Ať se z kódu nepráší!

The New Distrowatch – Bachelor's thesis (SK)
The New Distrowatch – Bachelor's thesis (SK)The New Distrowatch – Bachelor's thesis (SK)
The New Distrowatch – Bachelor's thesis (SK)Jakub Žitný
 
Cucumber - Testovanie webových aplikácií
Cucumber - Testovanie webových aplikáciíCucumber - Testovanie webových aplikácií
Cucumber - Testovanie webových aplikáciíPeter Študent
 
SecureCam Program Guide
SecureCam Program GuideSecureCam Program Guide
SecureCam Program Guideguest146c167
 
Mobile first! Plynulý workflow - AIR
Mobile first! Plynulý workflow - AIRMobile first! Plynulý workflow - AIR
Mobile first! Plynulý workflow - AIRJuraj Michálek
 
Samuel Hopko & Daniel Rajčan - Cloud Computing
Samuel Hopko & Daniel Rajčan - Cloud ComputingSamuel Hopko & Daniel Rajčan - Cloud Computing
Samuel Hopko & Daniel Rajčan - Cloud ComputingDavinci software
 
Prvá hodina zoznámenie s kurzom
Prvá hodina   zoznámenie s kurzomPrvá hodina   zoznámenie s kurzom
Prvá hodina zoznámenie s kurzomĽuboš Beran
 
Require.JS & Backbone.JS
Require.JS & Backbone.JSRequire.JS & Backbone.JS
Require.JS & Backbone.JSsrigi
 
Matúš Jančík: Programuj rýchlejšie, meraj presnejšie
Matúš Jančík: Programuj rýchlejšie, meraj presnejšieMatúš Jančík: Programuj rýchlejšie, meraj presnejšie
Matúš Jančík: Programuj rýchlejšie, meraj presnejšieMichal Chabada
 
Prezentácia: Diplomový seminár 2
Prezentácia: Diplomový seminár 2Prezentácia: Diplomový seminár 2
Prezentácia: Diplomový seminár 2guest3604661
 
Počítačová podpora procesného modelovania s pomocou BPMN
Počítačová podpora procesného modelovania s pomocou BPMNPočítačová podpora procesného modelovania s pomocou BPMN
Počítačová podpora procesného modelovania s pomocou BPMNMiroslav Reiter
 
Processing workshop intro
Processing workshop introProcessing workshop intro
Processing workshop introJuraj Bednar
 
Debian na minimum | Energo TT Live 2012
Debian na minimum | Energo TT Live 2012Debian na minimum | Energo TT Live 2012
Debian na minimum | Energo TT Live 2012Erich Stark
 
Marek Lichtner - Používať alebo nepoužívať ORM vo webových aplikáciách?
Marek Lichtner - Používať alebo nepoužívať ORM vo webových aplikáciách?Marek Lichtner - Používať alebo nepoužívať ORM vo webových aplikáciách?
Marek Lichtner - Používať alebo nepoužívať ORM vo webových aplikáciách?webelement
 

Ähnlich wie Ať se z kódu nepráší! (20)

The New Distrowatch – Bachelor's thesis (SK)
The New Distrowatch – Bachelor's thesis (SK)The New Distrowatch – Bachelor's thesis (SK)
The New Distrowatch – Bachelor's thesis (SK)
 
Php sec
Php secPhp sec
Php sec
 
Cucumber - Testovanie webových aplikácií
Cucumber - Testovanie webových aplikáciíCucumber - Testovanie webových aplikácií
Cucumber - Testovanie webových aplikácií
 
SecureCam Program Guide
SecureCam Program GuideSecureCam Program Guide
SecureCam Program Guide
 
Mobile first! Plynulý workflow - AIR
Mobile first! Plynulý workflow - AIRMobile first! Plynulý workflow - AIR
Mobile first! Plynulý workflow - AIR
 
Samuel Hopko & Daniel Rajčan - Cloud Computing
Samuel Hopko & Daniel Rajčan - Cloud ComputingSamuel Hopko & Daniel Rajčan - Cloud Computing
Samuel Hopko & Daniel Rajčan - Cloud Computing
 
Prvá hodina zoznámenie s kurzom
Prvá hodina   zoznámenie s kurzomPrvá hodina   zoznámenie s kurzom
Prvá hodina zoznámenie s kurzom
 
Require.JS & Backbone.JS
Require.JS & Backbone.JSRequire.JS & Backbone.JS
Require.JS & Backbone.JS
 
Android libraries
Android librariesAndroid libraries
Android libraries
 
Matúš Jančík: Programuj rýchlejšie, meraj presnejšie
Matúš Jančík: Programuj rýchlejšie, meraj presnejšieMatúš Jančík: Programuj rýchlejšie, meraj presnejšie
Matúš Jančík: Programuj rýchlejšie, meraj presnejšie
 
Prezentácia: Diplomový seminár 2
Prezentácia: Diplomový seminár 2Prezentácia: Diplomový seminár 2
Prezentácia: Diplomový seminár 2
 
Počítačová podpora procesného modelovania s pomocou BPMN
Počítačová podpora procesného modelovania s pomocou BPMNPočítačová podpora procesného modelovania s pomocou BPMN
Počítačová podpora procesného modelovania s pomocou BPMN
 
Synopsi Barcamp
Synopsi BarcampSynopsi Barcamp
Synopsi Barcamp
 
Synopsi Barcamp
Synopsi BarcampSynopsi Barcamp
Synopsi Barcamp
 
Processing workshop intro
Processing workshop introProcessing workshop intro
Processing workshop intro
 
Debian na minimum | Energo TT Live 2012
Debian na minimum | Energo TT Live 2012Debian na minimum | Energo TT Live 2012
Debian na minimum | Energo TT Live 2012
 
Marek Lichtner - Používať alebo nepoužívať ORM vo webových aplikáciách?
Marek Lichtner - Používať alebo nepoužívať ORM vo webových aplikáciách?Marek Lichtner - Používať alebo nepoužívať ORM vo webových aplikáciách?
Marek Lichtner - Používať alebo nepoužívať ORM vo webových aplikáciách?
 
347471_zaverecny_ukol
347471_zaverecny_ukol347471_zaverecny_ukol
347471_zaverecny_ukol
 
Tastypie
TastypieTastypie
Tastypie
 
Magsa-generovanie
Magsa-generovanieMagsa-generovanie
Magsa-generovanie
 

Mehr von Juraj Michálek

Rust Embedded Development on ESP32 and basics of Async with Embassy
Rust Embedded Development on ESP32 and basics of Async with EmbassyRust Embedded Development on ESP32 and basics of Async with Embassy
Rust Embedded Development on ESP32 and basics of Async with EmbassyJuraj Michálek
 
Embedded Development on ESP32 - FEKT VUT - UREL
Embedded Development on ESP32 - FEKT VUT - URELEmbedded Development on ESP32 - FEKT VUT - UREL
Embedded Development on ESP32 - FEKT VUT - URELJuraj Michálek
 
Embedded Rust on ESP2 - Rust Linz
Embedded Rust on ESP2 - Rust LinzEmbedded Rust on ESP2 - Rust Linz
Embedded Rust on ESP2 - Rust LinzJuraj Michálek
 
How Open Source Community and Espressif made it possible to use Rust language...
How Open Source Community and Espressif made it possible to use Rust language...How Open Source Community and Espressif made it possible to use Rust language...
How Open Source Community and Espressif made it possible to use Rust language...Juraj Michálek
 
C language in our world 2019
C language in our world 2019C language in our world 2019
C language in our world 2019Juraj Michálek
 
C language in our world 2017
C language in our world 2017C language in our world 2017
C language in our world 2017Juraj Michálek
 
Continuous Delivery - FIT VUT
Continuous Delivery - FIT VUTContinuous Delivery - FIT VUT
Continuous Delivery - FIT VUTJuraj Michálek
 
C language in our world 2016
C language in our world 2016C language in our world 2016
C language in our world 2016Juraj Michálek
 
C++ and Software Engineering 2015
C++ and Software Engineering 2015C++ and Software Engineering 2015
C++ and Software Engineering 2015Juraj Michálek
 
C language in our world 2015
C language in our world 2015C language in our world 2015
C language in our world 2015Juraj Michálek
 
Bigger & Better RnD - GeeCON.cz 2014
Bigger & Better RnD - GeeCON.cz 2014Bigger & Better RnD - GeeCON.cz 2014
Bigger & Better RnD - GeeCON.cz 2014Juraj Michálek
 
Gradle and build systems for C language
Gradle and build systems for C languageGradle and build systems for C language
Gradle and build systems for C languageJuraj Michálek
 
The story behind PF2014 - Cordova
The story behind PF2014 - CordovaThe story behind PF2014 - Cordova
The story behind PF2014 - CordovaJuraj Michálek
 
PowerShell from *nix user perspective
PowerShell from *nix user perspectivePowerShell from *nix user perspective
PowerShell from *nix user perspectiveJuraj Michálek
 
Ať se z kódu nepráší! 2013
Ať se z kódu nepráší! 2013Ať se z kódu nepráší! 2013
Ať se z kódu nepráší! 2013Juraj Michálek
 

Mehr von Juraj Michálek (20)

Rust Embedded Development on ESP32 and basics of Async with Embassy
Rust Embedded Development on ESP32 and basics of Async with EmbassyRust Embedded Development on ESP32 and basics of Async with Embassy
Rust Embedded Development on ESP32 and basics of Async with Embassy
 
Embedded Development on ESP32 - FEKT VUT - UREL
Embedded Development on ESP32 - FEKT VUT - URELEmbedded Development on ESP32 - FEKT VUT - UREL
Embedded Development on ESP32 - FEKT VUT - UREL
 
Embedded Rust on ESP2 - Rust Linz
Embedded Rust on ESP2 - Rust LinzEmbedded Rust on ESP2 - Rust Linz
Embedded Rust on ESP2 - Rust Linz
 
How Open Source Community and Espressif made it possible to use Rust language...
How Open Source Community and Espressif made it possible to use Rust language...How Open Source Community and Espressif made it possible to use Rust language...
How Open Source Community and Espressif made it possible to use Rust language...
 
C language in our world 2019
C language in our world 2019C language in our world 2019
C language in our world 2019
 
C language in our world 2017
C language in our world 2017C language in our world 2017
C language in our world 2017
 
Continuous Delivery - FIT VUT
Continuous Delivery - FIT VUTContinuous Delivery - FIT VUT
Continuous Delivery - FIT VUT
 
C language in our world 2016
C language in our world 2016C language in our world 2016
C language in our world 2016
 
Story behind PF 2016
Story behind PF 2016Story behind PF 2016
Story behind PF 2016
 
C++ and Software Engineering 2015
C++ and Software Engineering 2015C++ and Software Engineering 2015
C++ and Software Engineering 2015
 
C language in our world 2015
C language in our world 2015C language in our world 2015
C language in our world 2015
 
C++ in our world
C++ in our worldC++ in our world
C++ in our world
 
Bigger & Better RnD - GeeCON.cz 2014
Bigger & Better RnD - GeeCON.cz 2014Bigger & Better RnD - GeeCON.cz 2014
Bigger & Better RnD - GeeCON.cz 2014
 
Gradle and build systems for C language
Gradle and build systems for C languageGradle and build systems for C language
Gradle and build systems for C language
 
The story behind PF2014 - Cordova
The story behind PF2014 - CordovaThe story behind PF2014 - Cordova
The story behind PF2014 - Cordova
 
There is more to C 2013
There is more to C 2013There is more to C 2013
There is more to C 2013
 
PowerShell UIAtomation
PowerShell UIAtomationPowerShell UIAtomation
PowerShell UIAtomation
 
PowerShell from *nix user perspective
PowerShell from *nix user perspectivePowerShell from *nix user perspective
PowerShell from *nix user perspective
 
Ať se z kódu nepráší! 2013
Ať se z kódu nepráší! 2013Ať se z kódu nepráší! 2013
Ať se z kódu nepráší! 2013
 
There is more to C
There is more to CThere is more to C
There is more to C
 

Ať se z kódu nepráší!

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n