ekb.py - Python VS ...

865 views

Published on

Автор - Илья Шабалин

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
865
On SlideShare
0
From Embeds
0
Number of Embeds
306
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ekb.py - Python VS ...

  1. 1. Python vs. ? Илья Шабалин, Exadel, Екатеринбург
  2. 2. BufferedReader myFile = new BufferedReader( new FileReader(filename)); while ( true ) { String line = myFile.readLine(); if (line == null ) { break ; } System.out.println(line); } Чтение из файла: Java
  3. 3. for line in open (filename): print line Чтение из файла: Python
  4. 4. $ handle = @ fopen ( $ filename ) ; if ( $ handle ) { while (( $ buffer = fgets ( $ handle , 4096 )) !== false ) { echo $ buffer ; } if ( ! feof ( $ handle )) { echo " Error: unexpected fgets() fail n "; } fclose ( $ handle ) ; } Чтение из файла: PHP
  5. 5. public class EtmDecorator implements InvocationHandler { private final Object obj; public static Object newInstance(Object obj) { return Proxy.newProxyInstance( obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new EtmDecorator(obj)); } public EtmDecorator(Object obj) { this .obj = obj; } @ Override public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { EtmPoint point = EtmManager.getEtmMonitor().createPoint(m.getName()); try { return m.invoke(obj, args); } catch (InvocationTargetException e) { throw e.getCause(); } finally { point.collect(); } } } Декоратор: Java
  6. 6. def measure (func): @ functools.wraps (func) def wrapper (*args, **kwargs): point = create_measurement_point(func.__name__) try : return func(*args, **kwargs) finally : point.collect() return wrapper Декоратор: Python
  7. 7. class Decorator { private $ obj ; function __construct ( $ obj ) { $ this -> obj = $ obj ; } function __call ( $ method , $ args ) { $ point = createMeasurementPoint ( $ method ) ; try { $ rv = call_user_func_array ( array ( $ this -> obj, $ method ) , $ args ) ; $ point -> collect () ; return $ rv ; } catch ( Exception $ e ) { $ point -> collect () ; throw $ e ; } } } Декоратор: PHP
  8. 8. CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Campaign> campaigns = cb.createQuery(Campaign. class ); Root<Campaign> from = campaigns.from(Campaign. class ); campaigns.select(from); campaigns.where(cb.equal(from.get( &quot;name&quot; ), name)); TypedQuery<Campaign> query = entityManager.createQuery(campaigns); return query.getSingleResult(); ORM: Java
  9. 9. return Session.query(Campaign). filter (Campaign.name==name).first() ORM: Python
  10. 10. Вопросы?

×