ht16 - da361a - oop med python

Post on 09-Jan-2017

207 Views

Category:

Education

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

OOP med Python… och att skriva bra kod

Dagens föreläsningOOAD

Att skriva bra kod

OOP

OOA => OOD => OOP

Presenter
Presentation Notes
Analys => Vilka objekt finns Design => Hur hänger dessa ihop? => Diagram

Vad kan ni om OOA?

Vad kan ni om OOD?

PEPPython Enhancement Proposalshttps://www.python.org/dev/peps/

Presenter
Presentation Notes
 guiding principles for Python's design

De viktigaste punkternaBeautiful is better than ugly.

Simple is better than complex.

Readability counts.

If the implementation is hard to explain, it's a bad idea.

PEP 8https://www.python.org/dev/peps/

PEP 8 är en style-guide för att skriva Python-kod

Det viktigaste med PEP 8

Kod läses många fler gånger än den skrivs

Samstämmighet för de som skriver/läser kod

Undantag mot PEP 8? När?

Lyssna på omgivningen (kanske ert företag har andra designregler för kod?)

Minskar läsbarheten

De viktigaste punkterna!

4st mellanslag (alt. TAB)

Mixa aldrig tabbar och mellanslag

Ha maximalt 79 tecken per rad, annars radbryt

Använd blanka rader med måtta

Dålig radlängd

Bra radlängd #1

Bra radlängd #2

Radbrytningar

ImportsDåligt

Bra

BlankstegDåligt

Blankstegbra

Dåligt Bra

Kommentarer

RekommendationerBra Dåligt

Kontrollera din kodhttp://pep8online.com/Eller installera pep8 genom pip

Automatisera PEP8http://stackoverflow.com/questions/14328406/tool-to-convert-python-code-to-be-pep8-compliant

Cheat sheethttps://gist.github.com/RichardBronosky/454964087739a449da04

OOP med Python

Procedural programming is a method of writing software. It is a programming practice centered on the

procedures or actions that take place in a program

Procedural programming is made up of one or more proceduresProcedures operate on data items that are separate from the procedure

Data items are passed from one procedure to another

Focus is on the creation of procedures that operate on the program’s data

Object-oriented programming is centered on objects. Objects are created from abstract

data types that encapsulate data and function together.

OOPAn object is a software entry that contains both data and procedures

Data contained in an object is known as the object’s data attributes

Procedures that an object performs are known as methods

A class is code that specifies data attributes and methods for a particular

type of data.

top related