Syntax highlighter

2009-08-31

求めているもの、求められているもの

仕事探してほぼ丸2ヶ月。未だ無職なわけだが、2度ほど面接(といっても電話)を受けた。ちなみに、何かの間違いでどちらも同じ会社。
結果は未だ無職ということだ。

ただ、何度受けてもその会社の求めているものが満たせるとは思えないので、まぁ、いいのだろう。(泣いてないからね。。。)
Javaにおけるfinalキーワードの意味は?assertの意味は?ifとassertの違いは?immutableクラスとは?
いやね、分かりますよ。日本語ならね。そげな勉強英語ではしておりませんので、ぱっとは答えられんがね。んで、言われたのが、Java開発者になりたいなら、コースを受けるべきだね、って。ああ、そうかい。

個人的に、プログラミングの本質は問題の解決にあると思っているので、開発言語にこだわったことないんだよね。言語の特徴を活かす事は好きだが。
なので、Java最高、デザインパターン必須、ってのは肌が受け付けない感じはする。2度とも同じ人だったと思うが、いわゆるオタクなかほりがする話し方だったし。(まぁ、デザインパターンは知ってて損はないと思うが。でもあれって突き詰めていくとそうなるって物に名前が付いてるだけって気もするが)

Javaのプログラムが書ける人(幅が広い定義なるが)ではなく、Java言語の定義を知っている人がほしいなら募集要項にそう書いてほしい。
あぁ、負け犬の遠吠えさ。

2009-08-30

圧倒的じゃないか

某ガンダムの台詞ではない。
308議席獲得の民主党のこと。

初めて選挙権を行使しなかった(できなかったのだが)選挙。
それにしても、ネット(ぐらいしか情報源がない)でささやかれていることが本当で、この4年間の間に全部実現されたら、日本に帰れなくなるなぁ・・・
そもそも、個人献金とか西松建設の問題ってどうなったんだろう?今のところ容疑者扱いなのかね?真っ黒なグレーの人が総理大臣とか(そもそも政治家でそうではない人の方が少ないのかもしれないが)、日本列島は日本人だけのものではない発言の人が総理とかどうなんだろう?
国益のために動いてくれるならどっちでもいいんだけど、アメリカ寄りか、中韓寄りかの違いかね。

これだけ圧倒的な議席数をもたれたら、お手並み拝見では済まない状況ではないかと思ったり思わなかったり。

2009-08-27

総選挙

民主党の財源の話。

民主党は現行制度を抜本的に改め、職業に関係なくすべての人が同じ制度に加入する「一元化」を目指す。収入の15%の保険料を納付し、将来はそれに見合った額を受給する「所得比例年金」に「最低保障年金」を組み合わせる構想だ。

ソースはここ
おまけ

収入の15%…

       ヽ|/
     / ̄ ̄ ̄`ヽ、
    /         ヽ
   /  \,, ,,/    |
   | (●) (●)|||  |
   |  / ̄⌒ ̄ヽ U.|   ・・・・・・・・ゴクリ。
   |  | .l~ ̄~ヽ |   |
   |U ヽ  ̄~ ̄ ノ   |
   |    ̄ ̄ ̄    |

計算式
額面給料:400万(結構もらってんな)
民主党案:400 x 0.15 = 60万

これに対して、所得税、住民税、その他もろもろがかかる。
「憶測」
給料:400万
所得税(5%):20万
地方税(10%):40万
健保税(10%):40万 (これは減るのか?)
民主案(15%):60万

手取り額(年):240万
手取り額(月):20万

300万なら、月の手取りは15万に、200万(いわゆるワープア)なら、10万に。アルバイトも収入になるので、単純に時給 x 15%が税金に。
ちなみに、消費税は別途買い物すれば取られます。

うわさによると、これが施行されるのは政権を取った4年後。そのときには、民主党が野党になっている可能性がある。っで、野党としてこの法律のことを言及するとかなんとか。
まぁ、さすがにそれはうわさでしかないが。ありえそうな話。

TVでは民主300議席なんて騒がれてるらしいけど、あなたはそれでも民主党にいれますか?

2009-08-20

Composite pattern

[category]
Structural pattern

[brief description]
This pattern "compose" objects into tree structures to represent part-whole hierarchies.

[detail description]
This pattern provides a tree structures data model. Think about directories and files, directories are composite and files are leafs. Directories can have files in themselves as their children.

[expression in UML]

┌─────────┐
│ Component │
├─────────┤
├─────────┤0..*
│ + operation() │────────―─┐
│ + add() │child │
│ + remove() │ │
│ + getChild() │ │
└─────────┘ │
△ │
│ │
┌──────┴───────┐ │
│ │ │
┌────┴───┐ ┌────┴────┐ │
│ Leaf │ │ Composite │ │
├────────┤ ├─────────┤ │
├────────┤ ├─────────┤ │
│ + operation() │ │ + operation() │ 1 │
└────────┘ │ + add() │◇─┘
│ + remove() │ parent
│ + getChild() │
└─────────┘

[sample code]

(C++)

#include <stdexcept>
#include <iostream>
#include <vector>
#include <string>

enum Type
{
dic,
file
};

class Component
{
public:
Component() {}
Component(Type t_, const char* name_)
: t(t_), name(name_)
{}
virtual ~Component() {}
virtual void operation() {}
Type getType() { return t; }
const char* getName() { return name; }
virtual void add(Component* c) { throw std::runtime_error("This method is not implemented."); }
virtual void remove() { throw std::runtime_error("This method is not implemented."); }
virtual std::vector getChild()
{ throw std::runtime_error("This method is not implemented."); }
virtual int getSize() { throw std::runtime_error("This method is not implemented."); }

private:
Type t;
const char* name;
};

class Directory
: public Component
{
public:
Directory(const char* name)
: Component(dic, name)
{}
virtual ~Directory()
{
for (int i = 0; i < children.size(); i++) {
delete children[i];
}
}
virtual void operation()
{
std::cout << getName() << std::endl;
}
virtual void add(Component* c)
{
children.push_back(c);
}
virtual void remove()
{
Component* c = *(children.end() - 1);
delete c;
children.pop_back();
}
virtual std::vector getChild() { return children; }
virtual int getSize() { return children.size(); }

private:
std::vector children;
int size;
};

class File
: public Component
{
public:
File(const char* name)
: Component(file, name)
{}
virtual ~File() {}

virtual void operation() { std::cout << getName() << std::endl; }
};

void printTree(Component* com, const std::string indent)
{
std::cout << indent;
if (file == com->getType()) {
com->operation();
} else if (dic == com->getType()) {
com->operation();
int size = com->getSize();
std::vector children = com->getChild();
for (int i = 0; i < size; i++) {
Component* c = children[i];
printTree(c, indent + " ");
}
}
}

int main(int, char**)
{
Component* d1 = new Directory("dic 1");
Component* f1 = new File("file 1");

d1->add(f1);

Component* d2 = new Directory("dic 2");
d1->add(d2);

Component* f2 = new File("file 2");
d2->add(f2);

printTree(d1, "");

return 0;
}

Factory method pattern

[category]
Creational pattern.

[brief description]
This pattern provides methods to create objects which has superclass and a lot of derivatives.

[detail description]
This pattern solves the problem that other creation pattern has. (The problem is specifying the exact class of object that will be created)
This pattern separate the method to create an object so that client do not need to specify the class of object.

[expression in UML]

┌──────────┐
│ Creator │
├──────────┤
├──────────┤
│+ factoryMethod() │
│ : Product │
└──────────┘



┌───────┐ ┌──────────┐
│ Product │ │ CroncretCreator │
├───────┤ <------------ ├──────────┤
├───────┤ ├──────────┤
└───────┘ │+ factoryMethod() │
│ : Product │
└──────────┘


[sample code]

(C++)

#include <iostream>
#include <stdexcept>

// this class is interface of product
class Car
{
public:
virtual ~Car() {}
virtual void run() = 0;
};

// these are concret products
class SportCar
: public Car
{
public:
SportCar() { }
virtual ~SportCar() {}

virtual void run()
{
std::cout << "I'm a sport car." << std::endl;
std::cout << "I can run 300 km/h." << std::endl;
}
};

class LuxuryCar
: public Car
{
public:
LuxuryCar() { }
virtual ~LuxuryCar() {}

virtual void run()
{
std::cout << "I'm a luxury car." << std::endl;
std::cout << "You can feel very comfortable." << std::endl;
}
};

class NormalCar
: public Car
{
public:
NormalCar() {}
virtual ~NormalCar() {}

virtual void run()
{
std::cout << "I'm a normal car." << std::endl;
std::cout << "I'm a resonable price." << std::endl;
}
};

enum CarType
{
Sport,
Luxury,
Normal,
Other
};

class CarFactory
{
public:
static Car* createCar(CarType type)
{
switch (type) {
case Sport: return new SportCar();
case Luxury: return new LuxuryCar();
case Normal: return new NormalCar();
}
throw std::invalid_argument("We don't know how to make this car.");
}
};

int main(int, char**)
{
try {
Car* car1 = CarFactory::createCar(Sport);
Car* car2 = CarFactory::createCar(Luxury);
Car* car3 = CarFactory::createCar(Normal);

car1->run();
car2->run();
car3->run();
// the factory throws exception
Car* car4 = CarFactory::createCar(Other);
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
return 0;
}

Adapter pattern

一応自分の言葉で説明できるように、自分なりの解釈を書くようにしてるので、間違いがたぶんにあると思う。

[category]
Structural pattern.

[brief description]
This pattern translates one interface for a class into compatible interface.
=> Wrapper

[detail description]
Adapter class provides interfaces to client from incompatible classes or, this is my opinion, a new interface wrapped around a simple interface such as MFC. cf) MFC wraps Windows API about C++ interface, I think, I've never used MFC... --;

[expression in UML]
┌───────┐
│ Adaptee │
├───────┤
├───────┤
│+ methodB() │
└───────┘



┌───────┐ ┌───────┐
│ Client │──────>│ Adapter │
├───────┤ ├───────┤
│- adapter │ │- adaptee │
│ : Adapter │ │ : Adaptee │
├───────┤ ├───────┤
│+ doWork() │ │+ methodA() │
└───────┘ └───────┘
│ │
│ │
↓ ↓
┌─ doWork() ───┐ ┌─ methodA() ───┐
│ │ │ │
│ adapter.methodA() │ │ adaptee.methodB() │
│ │ │ │
└──────────┘ └──────────┘


[sample code]

(C++)

#include <iostream>
//---- this is adaptee classes for other file
struct Point
{
Point(int x_, int y_) : x(x_), y(y_) {}
int x;
int y;
};

std::ostream& operator<<(std::ostream& ost, Point p)
{
ost << "(" << p.x << "," << p.y << ")";
return ost;
}

class LinePrinter
{
public:
void printLine(Point* a, Point* b)
{
std::cout << "draw line from " << *a << " to " << *b << std::endl;
}

void printRectangle(Point* a, Point* b)
{
std::cout << "draw rectangle from " << *a << " to " << *b << std::endl;
}
};
//---- end adaptee classed

//---- these are adapter
class Shape
{
public:
Shape(int x1, int x2, int y1, int y2)
: p1(x1, y1), p2(x2, y2)
{}
virtual ~Shape() {}

virtual void draw() = 0;
protected:
void setPrinter(LinePrinter* printer_)
{
printer = printer_;
}
LinePrinter* printer;

Point p1;
Point p2;
};

class Line
: public Shape
{
public:
Line(int x1, int x2, int y1, int y2)
: Shape(x1, x2, y1, y2)
{
setPrinter(new LinePrinter());
}
virtual ~Line() {}

virtual void draw()
{
printer->printLine(&p1, &p2);
}
};

class Rectangle
: public Shape
{
public:
Rectangle(int x1, int x2, int y1, int y2)
: Shape(x1, x2, y1, y2)
{
setPrinter(new LinePrinter());
}
virtual ~Rectangle() {}

virtual void draw()
{
printer->printRectangle(&p1, &p2);
}
};
//---- end adapter

int main(int, char**)
{
Shape *line = new Line(0, 0, 10, 5);
Shape *rect = new Rectangle(0, 0, 10, 10); // must be square

line->draw();
rect->draw();

delete line;
delete rect;

return 0;
}

デザインパターンのお勉強

仕事を探す上で、どうにもデザインパターンがキーワードになるので、昔の本やら知識やらを総動員しつつ、勉強することにした。
いや、**日本語**でなら説明できるんだけど、英語と言われると難しいからなのだが。

っで、メモ帳代わりにブログを使用することにした。
なので、しばらく面白くも無い投稿が続くことになる。

2009-08-15

風雲たけし城

オランダのケーブルテレビのチャンネルの一つ(のが多い)、コメディーセントラルで「Takeshi's Castle」として放送された。
懐かしさのあまりテレビを占拠してみてしまったが、ダイジェスト版というか、なんというか、面白さ半減であった。(オランダ語の解説がよく分からなかったという説もある)

Wikipediaで調べてみると、この番組1986年から1989年まで放送されていたらしい。う~ん、保育園から小学校までか。
水鉄砲合戦とか、バレーボールを受け取るのとか、壁をぶち破るやつとかアトラクションを結構覚えている。

そこそこ面白かったのだが、1時間フルに放送してほしいのと、オランダ語字幕にして音声は日本語にしてほしいなぁ。

2009-08-09

Guitar Hero

Wii版ギターヒーローに最近はまっている。
昔ゲーセンで少しだけやった、コナミのギターフリークスとほぼ同じゲーム。
多分ギターヒーローはパクリか、OEMだろう。っが、これのすごいところはボーカル、ギター、ベース、ドラムとゲーム内でバンドが組めるところ。(全部別売りだけどね)

とりあえず、一通りの曲をクリアして、ハードに挑戦中。
使用ボタンが4つから5つになると一気にハードルが高くなる気がする。
はまる要素が結構あっておすすめ。

2009-08-01

しばらくはまったこと

be into ではなく、troubleの意味で・・・

最近何を思ったのかC++でちょっとしたものを作ってみたりしているのだが、それではまった。
はまったコード

class x
{
public:
typedef std::vector< x* > x_list;
x_list children() { return children_; }
void append(x* child()) { children().push_back(child); }
private:
x_list children_;
};

void do_something(x* parent, x* child)
{
x->append(child);
}

Java的感覚で見ると特に問題ないのだけど、C++的には意図した動作をしない。ある意味当たり前なんだけど、しばらくC++から離れていたのではまった・・・
問題h、メンバ関数children()が参照返しではなく値返しだということ。っで、append()の中でchildren()を呼び出しているので、children_に追加したくても、実際にはどこかにメモリーをリークさせながら消えていったという悲しい現実。
わざわざappend()の中でchildren()を呼ぶ必要があったかと言われると・・・
解決方法は簡単でchildren()の戻り値を「x_list&」にすればOK。

今後の備忘録のために、恥ずかしいミスをさらしておく・・・orz