2. • Expert
Python
Programming
is
a
super
cool
book!
– It
provides
very
pragma?c
knowledge
for
Python
programmers.
– It
provides
very
acute
insight
for
Other
language
programmer!
3. PyConJP
LT
(2011/08/27)
DeNA
Co.Ltd.,
Smartphone
SG
system
group.
Sphinx-‐Users.jp
/
eXtreme
Programming
Users
Group
Japan
Shibukawa
Yoshiki
4. Twicer:
@shibukawa
• Job
– Honda
R&D
→
DeNA
– I’m
playing
Smartphone
everyday!
• Community
– Sphinx-‐Users.jp
Organizer
– XPJUG
– PySpa
• Books
– Simple
and
Steady
Way
of
Learning
for
So`ware
Engineers(Gihyo)
– Expert
Python
Programming
(ASCII-‐MW)
– Pomodoro
Technique
illustrated
(ASCII-‐MW)
– The
Art
of
Community
(O’reilly
Japan)
:
web
13. • node.js
(hcp://nodejs.org)
– Good
interac?ve
shell
for
JavaScript
• Windows
– Use
binary
package
• Linux
– Use
apt-‐get
or
emerge
or
anything
• MacOSX
– Use
MacPorts
or
Homebrew
• npm
(hcp://npmjs.org)
– easy_install
for
nodejs
node.js
14. • I’m
using
Emacs.
Sorry
Tarek.
– js2-‐mode
is
good!
• hcp://code.google.com/p/js2-‐mode
• Download
source
and
M-‐x
byte-‐compile-‐file
• Add
following
line
following
lines:
(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '(".js$" . js2-mode))
• Other
DeNA
guys
are
using
Emacs,
Vim,
Eclipse,
WebStorm.
Emacs js2-‐mode
16. • Global
namespace
is
important
than
Python
– JavaScript
has
only
one
global
area.
• 1.
Self-‐invoke
func?on
(function() {
// This area is private!
})();
• 2.
Export
only
accessor
methods
var getter;
(function() {
var privateVar = 100;
getter = function() {return privateVar;};
})();
17. • This
is
good
technique
for:
– Inser?on
ini?alize
code.
– Bridging
incompa?bility
between
browsers.
– Crea?ng
unit
test
for
browser
on
node.js.
function a() {
// initialize code or check compatibility
a = function() {
// function logic it is used always
};
};
23. • Original
JavaScript
doesn’t
have
“import”
mechanism.
– It
is
important
for
crea?ng
large
so`ware.
– CommonJS
proposes
good
design.
• It
is
used
by
node.js
and
ngcore.
• jQuery
builder,
closure
compiler…
many
libraries
are
created
with
many
source
files.
– Combine
all
needed
sources.
24. • It
supports
require
and
exports.
• ngCore
build
tool
treats
source
code
like
this:
var Button = require(‘./UI/Button’).Button;
exports.MyWindow = function() {
this.title = “hello world”;
this.size = [100, 100, 400, 200];
};
25. • It
supports
require
and
exports.
• ngCore
build
tool
treats
source
code
like
this:
MODULES[“modulename”] = (function() {
var exports = {};
var require = function(file){ return MODULES[file]; };
var Button = require(‘./UI/Button’).Button;
exports.MyWindow = function() {
this.title = “hello world”;
this.size = [100, 100, 400, 200];
};
return exports;})();
27. • I
don’t
know
what
you
want
to
create.
• There
are
many
different
environment
today.
– My
recommend
environment
is
ngCore.
You
can
create
Android
and
iOS
games
from
same
source.
Future,
ngCore
will
support
HTML5.
ngCore
29. Of
course!!
• SCM
is
important
for
JavaScript
too!
• I
love
mercurial.
During
using
git,
I
some?mes
got
error
because
I
type
hg
instead
of
git.
JavaScript
33. • Famous
tool
in
JS
community
is
JSDoc
series.
– JSDoc-‐toolkit
2.4
is
the
latest
stable
version.
– JSDoc
3
is
now
crea?ng.
– node-‐jsdoc-‐toolkit
is
easy
to
use
and
fast!
• hcps://github.com/p120ph37/node-‐jsdoc-‐toolkit
• Do
you
like
auto
generated
document?
I
don’t
like.
It
is
hard
to
write
good
document.
node-‐jsdoc-‐toolkit
34. • Sphinx
is
good
tool
for
almost
all
programmers!
– You
can
create
becer
document!
– Easy
to
learn,
easy
to
write.
hard
to
write
Plugin…
• I’m
crea?ng
CommonJS-‐domain
and
CommonJS-‐
autodoc
plugin
now.
Please
wait!
Sphinx CommonJS
36. • I’m
using
Jasmine.
• If
your
code
run
in
browser
or
mobile
device,
you
can
run
logic
test
on
node.js.
– Fast
feedback!
Fast
development
cycle.
– You
can
install
node-jasmine
via
npm.
– “Func?ons
that
rewrites
thyself”
technique
is
useful!
38. Of
course!!
• Python’s
strategy
of
op?miza?on
is
as
same
as
JavaScript
too!
Python JS
39. • Each
JavaScript
engines
have
different
character:
– V8
– V8
for
Android
– Safari
– Safari
for
iOS
– WebView
for
iOS
– Firefox
– Internet
Explorer…
• You
have
to
profile
on
the
environments
you
use.
JS
41. • Asynchronous
is
the
most
important
part
of
JS
– It
is
a
pit
fall
Java
programmer
fall
– Callback
hell!
– Sequen?al
source
code
is
more
readable
and
easy
to
understand.
42. • jsDeffered
– hcp://cho45.stuawsc.com/jsdeferred/
next(function() { /* task 1 */ }).
next(function() { /* task 2 */ });
chain(
function() { /* task 1 */ },
function() { /* task 2 */ }
);
– Sorry
I
have
never
used
it…
– Maybe
twisted
programmers
familiar
with
this.
43. • Try
to
write
following
“Counter”
class.
var counter = new Counter();
fs.writeFile(“METADATA”, data1, counter.newTask());
fs.writeFile(“REQUEST”, data2, counter.newTask());
counter.wait(function() {
// All task is finished.
});
• It
works
similar
to
sleep
sort.
Run
all
tasks
at
the
same
?me
and
check
only
the
task
end.
44. • All
func?ons
which
uses
Async
call
must
receive
callback
func?on.
– If
not,
caller
can’t
know
whether
all
tasks
are
finished
or
not
Func?on
caller
Callback
func?on
Pass
Async
46. • Expert
Python
Programming
is
super
cool
book!
– It
provides
very
pragma?c
knowledge
for
Python
programmers.
– It
provides
very
acute
insight
for
Other
language
programmer!