понедельник, 27 сентября 2010 г.
Objects have failed
Interesting view on object-oriented programming languages. Full text is here. I was always wondering how could someone do such a ugly language as C++ from such a nice language as C. The author goes further and says that "programmer in Fortran can write a Fortran program in any language", or something like that. He describes different problems of modern object-oriented languages and he seems to be right. I doubt that FOL-based or LISP-like languages will be successful as general-purpose languages in this decade... However, it would be interesting to see their further develoment.
среда, 22 сентября 2010 г.
Unix as literature
I've just got an excellent link from my workmate Oleg: The Elements Of Style: UNIX As Literature( the same text in Russian, original is better). It's rather interesting: a man with humanitarian education finds Unix more simple and effective then Windows NT (the article dates to 1999). I think I should mention this article to our students. They complain of Unix-like systems being too uncomfortable for them :)
KDE 4.5.1 - Konqueror is a bit better
I've just updated my FreeBSD desktop. I haven't noticed big changes in KDE 4.5.1 yet, however, some small updates really matter. Now we have useful adblock-like feature in konqueror - I can block any frame/image I like and use some public adblock lists. However, konqueror can't block Flash objects. I'd like it to block them too...
And as always, Google Buzz doesn't work with konqueror. It's not suitable.
I'd like to try rekonq 0.6, but there is only 0.5 version in ports tree... WebKit-based browser it seems should be better in JavaScript processing.
And as always, Google Buzz doesn't work with konqueror. It's not suitable.
I'd like to try rekonq 0.6, but there is only 0.5 version in ports tree... WebKit-based browser it seems should be better in JavaScript processing.
среда, 15 сентября 2010 г.
One interesting post about ORM
I've just found one interesting post about ORM - you may be interested in it. This post is rather old, but it is quite adequate even now. The link is here . Russian translation may be found at citforum.
OpenIndiana oi_147
Today we finally got the first release of OpenIndiana - new Illumos distribution, comparable to OpenSolaris binary distribution. I've just set it up and looked throw. Some interesting new things after my migration to FreeBSD (at times of OpenSolaris dev build 134) - interesting thing in zfs:
zfs diff:
It's quite convinient, however it would be really cool to make zfs diff on particular files :) Other things include DTrace udp and tcp probes and quite sensible improvements in NWAM. At least, it is usable now...
zfs diff:
# zfs diff -F rpool/ROOT/openindiana@install rpool/ROOT/openindiana
M / /
M / /var/pkg
M / /var/cache/cups
M / /var/cache/cups/rss
M / /var/adm
M / /dev
M / /etc
M / /var/cache/gdm
M / /var/svc/log
M / /etc/gconf/gconf.xml.defaults
M / /var/tmp
M / /etc/rc2.d
It's quite convinient, however it would be really cool to make zfs diff on particular files :) Other things include DTrace udp and tcp probes and quite sensible improvements in NWAM. At least, it is usable now...
понедельник, 6 сентября 2010 г.
Why do I dislike ORM?
"Any problem in computer science can be solved with another level of indirection"... Sometimes we receive too much indirection levels.
Let's try. First time I use psql:
Start with query:
Will it work? Of course, no. The reason is that we have implicit conversion to integer.
Let's try once more:
Now it worked. Ok.
Let's try to do something similar in Hibernate:
And...
Ok. Let's try select * from employees; update it and then select * again;
And results are:
Oops... Select didn't notice update... O, shit!!!
I had some more experiments: we had forgotten that criteriaQueries exists (they are not implemented in Hibernate JPA, may be they are included in some GlassFish jar, but I'm tired).
It's really easier to create DAO with JDBC. And embedded SQL in C is much easier to understand and debug then all this ORM things... I like to work with database. I understand how it works.
Don't do my life easier. I can create effective SQL myself! I spend more time learning different crutches!!!
Let's try. First time I use psql:
> \d employees
Table "public.employees"
Column | Type | Modifiers
----------+------------------------+--------------------------------------------------------
id | integer | not null default nextval('employees_id_seq'::regclass)
name | character varying(255) |
surname | character varying(255) |
dept | character(3) |
phone | character varying(15) |
hiredate | date |
job | character varying(255) |
salary | numeric(9,0) |
Indexes:
"employees_pkey" PRIMARY KEY, btree (id)
Start with query:
UPDATE employees set salary=salary*(1+2/100) WHERE salary<=5000
Will it work? Of course, no. The reason is that we have implicit conversion to integer.
Let's try once more:
UPDATE employees set salary=salary*(1.0+2.0/100) WHERE salary<=5000
Now it worked. Ok.
Let's try to do something similar in Hibernate:
Query q;
int updated;
q=em.createQuery("update Employees set salary=salary+:par*salary");
q.setParameter("par", new Float(1.1));
updated=q.executeUpdate();
And...
INFO: could not bind value '1.1' to parameter: 1; java.lang.Float cannot be cast to java.lang.Integer
Exception in thread "main" java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.Integer
at org.hibernate.type.IntegerType.set(IntegerType.java:41)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:38)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:67)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:49)
at testhybernate.Main.updateData(Main.java:57)
at testhybernate.Main.main(Main.java:33)
Ok. Let's try select * from employees; update it and then select * again;
...
em=emf.createEntityManager();
showData(em);
updateData(em);
showData(em);
...
protected static void showData(EntityManager em) {
Iteratorit;
Query q;
Listresult;
em.flush();
q=em.createQuery("from Employees");
result=q.getResultList();
it=result.iterator();
while(it.hasNext()){
Employees emp;
emp=(Employees)it.next();
System.out.println(emp);
}
}
private static void updateData(EntityManager em) {
Query q;
int updated;
q=em.createQuery("update Employees set salary=salary+1.1*salary");
updated=q.executeUpdate();
System.out.println("updated "+updated+ " entities");
}
And results are:
3 Steven King DIR 1986-01-01 Director 659
5 John Doe BAS 1985-07-10 Engineer 659
1 Elizabeth Bates SAL 2000-12-05 Manager 659
4 John Doe MNT 1989-06-01 Cleaner 659
6 Ken Green BAS 1994-07-02 Programmer 659
7 Sergey Spiridonov MNT 2002-07-02 System Administrator 659
updated 6 entities
3 Steven King DIR 1986-01-01 Director 659
5 John Doe BAS 1985-07-10 Engineer 659
1 Elizabeth Bates SAL 2000-12-05 Manager 659
4 John Doe MNT 1989-06-01 Cleaner 659
6 Ken Green BAS 1994-07-02 Programmer 659
7 Sergey Spiridonov MNT 2002-07-02 System Administrator 659
Oops... Select didn't notice update... O, shit!!!
I had some more experiments: we had forgotten that criteriaQueries exists (they are not implemented in Hibernate JPA, may be they are included in some GlassFish jar, but I'm tired).
It's really easier to create DAO with JDBC. And embedded SQL in C is much easier to understand and debug then all this ORM things... I like to work with database. I understand how it works.
Don't do my life easier. I can create effective SQL myself! I spend more time learning different crutches!!!
пятница, 3 сентября 2010 г.
DTrace: it's really cool to have it working in FreeBSD
I've just managed to enable DTrace in FreeBSD and was playing a bit with it.
I've added necessary for i386 options to my kernel config:
then run:
and received nothing good. The only working thing was dtrace -l. Everything other complained on uid_t in psinfo.d.
ctfdump showed a lot of stuff in kernel, but there was no uid_t. So, after adding the following line to my kernel config:
I got working dtrace!
So, now I can launch something like this...
I've added necessary for i386 options to my kernel config:
options KDTRACE_HOOKS
options DDB_CTF
then run:
make kernel WITH_CTF=1 KERNCONF=MyKern
and received nothing good. The only working thing was dtrace -l. Everything other complained on uid_t in psinfo.d.
ctfdump showed a lot of stuff in kernel, but there was no uid_t. So, after adding the following line to my kernel config:
makeoptions DEBUG=-g
I got working dtrace!
So, now I can launch something like this...
# dtrace -qn 'syscall::open:entry { printf ("%d %s %s\n",pid,execname,copyinstr(arg0)) ; }'
1297 sh /lib/libncurses.so.8
1297 sh /lib/libc.so.7
1297 id /etc/libmap.conf
1297 id /var/run/ld-elf.so.hints
1297 id /usr/lib/libbsm.so.3
1297 id /lib/libc.so.7
1296 make /usr/ports/Mk/bsd.licenses.mk
1296 make /usr/ports/Mk/bsd.sites.mk
1298 sh /etc/libmap.conf
1298 sh /var/run/ld-elf.so.hints
1298 sh /lib/libedit.so.7
1298 sh /lib/libncurses.so.8
1298 sh /lib/libc.so.7
1298 sysctl /etc/libmap.conf
1298 sysctl /var/run/ld-elf.so.hints
1298 sysctl /lib/libc.so.7
1296 make .depend
1299 sh /etc/libmap.conf
1299 sh /var/run/ld-elf.so.hints
1299 sh /lib/libedit.so.7
1299 sh /lib/libncurses.so.8
1299 sh /lib/libc.so.7
1299 rm /etc/libmap.conf
1299 rm /var/run/ld-elf.so.hints
1299 rm /lib/libc.so.7
1299 rm .
1299 rm /usr/ports/textproc/libxml2/work
1299 rm libxml2-2.7.7
Подписаться на:
Сообщения (Atom)