タグ

programmingに関するrawwellのブックマーク (81)

  • オブジェクト指向の骨頂は実世界のモデリングという原則, 今日のつぶやき - 32nd Diary(2009-04-15)

    めーるあどれす ruby -rbase64 -e'puts Base64.decode64 %q(dGFrYW5vMzJAZ21haWwuY29t)' ■ [Hack][Ruby] オブジェクト指向の骨頂は実世界のモデリングという原則via http://floralcompany.jp/archives/2009/04/helloworld_1.html http://twitter.com/hi_saito/status/1524994613 http://d.hatena.ne.jp/mzp/20090414/hello http://d.hatena.ne.jp/Yuichirou/20090414#1239705258 同じく違和感を感じた。 そもそもオブジェクト指向の目的はなんぞや、というと世界にある存在を抽象化してモデリングすること、のはずなんだよね。最近はよくわからない実装

    オブジェクト指向の骨頂は実世界のモデリングという原則, 今日のつぶやき - 32nd Diary(2009-04-15)
    rawwell
    rawwell 2009/04/19
    。 "Hello, World!" はオブジェクト指向で設計するようなものではない気がする。WelcomeクラスやGreetingクラスは実世界をオブジェクト指向で抽象化するのに自然な概念なんだろうか。
  • char から int へのキャスト時の問題 - Cube Lilac

    コメント - CLX C++ Libraries の動作確認 への対応.コメントで,以下のソースコードでうまく encode/decode されないと言う指摘がありました(ソースコードは若干改変). #include <iostream> #include <string> #include "clx/uri.h" int main() { std::string dest = clx::uri::encode("http://日語.com"); std::cout << "encode: " << dest << std::endl; std::cout << "decode: " << clx::uri::decode(dest) << std::endl; return 0; } これを手元の環境(cygwin gcc 4.1.2, VC++ 8.0)で実行すると,以下のような結果

    char から int へのキャスト時の問題 - Cube Lilac
    rawwell
    rawwell 2009/04/05
    『元の文字が ASCII 文字コードに収まらない*1 ような値のときに int へキャストすると,符号拡張のため上位の領域がすべて 1 で埋められてしまうようです.』
  • ビットシフトの落とし穴 - 算術シフトと論理シフト - 職業としてのプログラミング

    C言語には、ビットシフト演算子というものがあります。左シフト演算子(<<)と右シフト演算子(>>)です。同じビット演算でも、ビット単位の論理和(|)や論理積(&)、NOT(~)等はの方は、フラグ型の変数の処理で使われる事が多い気がしますが、ビットシフトの方は使用されるケースはあまりないかもしれません。 さて、このビットシフト演算子で時々問題になるのが、符号ビットが立っている時の右シフト演算です。見逃されがちなポイントは、 型によって挙動(算術シフトか論理シフトか)がかわることがある C言語の規格として、算術シフトか論理シフトかは不定 Nbitの算術シフトと2のN乗での除算は等価ではない といったところにあります。 算術シフト(shift arithmetic)と論理シフト(shift logical:又は0充填シフト)という言葉をご存知ない方のためにちょっと説明を書いておくと、シフトによっ

    rawwell
    rawwell 2009/04/05
    『signedの場合は算術右シフト(sarl)命令、unsignedの場合は、論理右シフト命令(shrl)になっているのが確認できます。』
  • charの落とし穴 - 暗黙の型変換と符号拡張 - 職業としてのプログラミング

    前回unsignedでよく陥りがちなバグについて触れました。今回はその続編で、char型での落とし穴として、いわゆる符号拡張(sign extension)と暗黙の型変換(inplicit conversion)について説明します。 次のコードの問題点はわかるでしょうか? typedef char value_t; #define INVALID 0xff /* valがINVALIDなら0、それ以外で1を返す */ int check(value_t val) { switch (val) { case INVALID: return 0; default: return 1; } 一見問題なさそうに思えますが、実際このコードをコンパイルして、valにINVALID(0xff)を指定しても1が帰ってきます。なぜでしょう? C言語のswitch分では、比較値はint型として扱われます。よっ

    rawwell
    rawwell 2009/04/05
    『変換時には符号拡張が行われ0xff(charの-1)は0xffffffff(intの-1:intが32bitの場合)となってしまいます。よって、0xffとは一致しないのです』
  • artima - The DCI Architecture: A New Vision of Object-Oriented Programming

    Object-oriented programming was supposed to unify the perspectives of the programmer and the end user in computer code: a boon both to usability and program comprehension. While objects capture structure well, they fail to capture system action. DCI is a vision to capture the end user cognitive model of roles and interactions between them. Objects are principally about people and their mental mode

  • Tail call - Wikipedia

    In computer science, a tail call is a subroutine call performed as the final action of a procedure.[1] If the target of a tail is the same subroutine, the subroutine is said to be tail recursive, which is a special case of direct recursion. Tail recursion (or tail-end recursion) is particularly useful, and is often easy to optimize in implementations. Tail calls can be implemented without adding a

    rawwell
    rawwell 2009/04/01
    Typically, the subroutines being called need to be supplied with parameters. The tail call optimizer needs to make sure that the call frame for A is properly set up before performing this optmization. For instance, on platforms where the call stack does not just contain the return address, but also
  • Do-less go-fast, revisited

    rawwell
    rawwell 2009/03/30
    "The moral, in this case, is that whenever you see a big, long run of if-elses, consider that someone has handed you an optimization opportunity."
  • Quine (computing) - Wikipedia

    A quine's output is exactly the same as its source code. A quine is a computer program that takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are "self-replicating programs", "self-reproducing programs", and "self-copying programs". A quine is a fixed point of an execution

    Quine (computing) - Wikipedia
  • エンディアンを考慮したメモリコピー - Cube Lilac

    blog をもう少しコンスタントに更新して行きたいなぁと言う事で,メモ代わり感覚で更新していきます. http://sourceforge.jp/tracker/index.php?func=detail&aid=15209&group_id=3652&atid=13543 の指摘を受けて.これに関わらず,多バイト長の変数(or その配列)から1バイトの配列へのコピー(あるいはその逆)を行う機会にしばしば遭遇するので,この機会に作成しておきます.最も,私の実行環境が全てリトルエンディアンなので,まともにテストできていないのですが・・・ エンディアンの判別 エンディアンの判別に関しては,http://www.math.kobe-u.ac.jp/~kodama/tips-C-endian.html で紹介されている方法を使用する事にします.具体的な方法は,__LITTLE_ENDIAN または

    エンディアンを考慮したメモリコピー - Cube Lilac
    rawwell
    rawwell 2009/03/23
    "多バイト長の変数(or その配列)から1バイトの配列へのコピー(あるいはその逆)を行う機会にしばしば遭遇するので,この機会に作成しておきます."
  • 西尾泰和のブログ: モナドを作るver. 0.1

    IOモナドは難しそうだったのでとりあえずMaybeモナドからはじめる。 >>> def Maybe(typ): class Foo(object): @classmethod def return_(_, x): return Just(x) @classmethod def bind(_, m, f): if isinstance(m, Nothing): return Nothing() elif isinstance(m, Just): return f(m.value) class Just(object): def __init__(self, x): assert isinstance(x, typ) self.value = x class Nothing(object): pass Foo.__name__ = "Maybe_%s" % typ.__name__ retur

    rawwell
    rawwell 2009/03/21
    "IOモナドは難しそうだったのでとりあえずMaybeモナドからはじめる。"
  • メタプログラミング:逆襲のニート

    ニートというのはダメな人じゃない。 ノーワークおじさんなのだ。 人間やればできる。 誰でも可能性の宝庫なのだ。 LISP、C++RubyPythonなどで、メタプログラミングを勉強できるみたいだ。 メタプログラミング 代表的なメタプログラミングの例はLISPのマクロである。 メタプログラミングの他の例としてはC++における「テンプレートメタプログラミング」などが挙げられる。 Rubyによるメタプログラミング演習 メタプログラミング ― つまり、"コードを生成するコード"を書くこと Pythonでのメタクラス・プログラミング ほとんどの読者は、オブジェクト指向プログラミングの継承、カプセル化、多態性といった概念については、すでによくご存じのことと思います。 といっても、いろいろな親を祖先とする何かのクラスからオブジェクトを生成する 操作は、通常、「単にそういう」ものとして捉えられています

    rawwell
    rawwell 2009/03/21
    "クラスがインスタンスの生成方法や振舞いを規定するのと同様に、 メタクラスはクラスの生成方法や振舞いを規定する。"
  • http://ja.doukaku.org/

  • Data is good, code is a liability

    Googler Peter Norvig gave a talk at industry day at CIKM 2008 that, despite my fascination with all things Peter Norvig, almost frightened me off by including the phrase "the Ultimate Agile Development Tool" in its title. The talk redeemed itself in the first couple minutes, citing Steve Yegge's "Good Agile, Bad Agile" and making it clear that Peter more meant being agile than Agile. His core poin

  • Function object - Wikipedia

    This article is about the computer programming concept of function objects. For functors in mathematics, see Functor. For the related concept in functional programming, see Functor (functional programming). This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. Find source

  • PerlPhrasebook - Python Wiki

    Introduction This phrasebook contains a collection of idioms, various ways of accomplishing common tasks, tricks and useful things to know, in Perl and Python side-by-side. I hope this will be useful for people switching from Perl to Python, and for people deciding which to choose. The first part of the phrasebook is based on Tom Christiansen's Perl Data Structures Cookbook. I have only been worki

  • codepad

    codepad is an online compiler/interpreter, and a simple collaboration tool. Paste your code below, and codepad will run it and give you a short URL you can use to share it in chat or email. Language: C C++ D Haskell Lua OCaml PHP Perl Plain Text Python Ruby Scheme Tcl

    rawwell
    rawwell 2009/03/01
    "codepad.org is an online compiler/interpreter, and a simple collaboration tool."
  • 正規表現に見切りをつけるとき

    Perl, Rubyなど手軽に使えるプログラミング言語に慣れてくると、あらゆるテキストデータの処理に正規表現(regular expression)を使ってしまいがちです。 けれど実は、正規表現の処理能力を超えるフォーマットというのが存在します。その典型的な例が、XMLやJSONのように、入れ子になったデータフォーマットです。

    rawwell
    rawwell 2009/01/27
    正規表現はショボい、ドラゴンブック読もうぜということですね
  • メモ化機構を切り離してみる - 技術をかじる猫

    メモ化の概念的には、結局のところ、引数パターンに対する辞書があって、一度やった処理は記録して使いまわす。 前回のものから、メモ化部分を抽出するだけしてみると、 def tarai(x, y, z): if x <= y: return y return tarai(memorize(x - 1, y, z), memorize(y - 1, z, x), memorize(z - 1, x, y)) table = {} def memorize(*args): global table if not args in table: table[args] = tarai(*args) return table[args] で、汎用化しようとしたときに、memorize 中の tarai と、tarai 中の memorize が邪魔になるので、昔見た C# のコード(元ネタ第35回CLR/

    メモ化機構を切り離してみる - 技術をかじる猫
    rawwell
    rawwell 2008/11/15
    "メモ化の概念的には、結局のところ、引数パターンに対する辞書があって、一度やった処理は記録して使いまわす。"
  • 2006-02-03

    2006-02-03 髪の毛を“どかす”というのはちょっと君… 日常 ウチの次男は寝癖がひどい。で、僕は「自分で髪の毛をとかしなさい」としょっちゅう言っている。すると、「わかった、どかすよ」と -- なぜか彼は「とかす」を「どかす」と発音するのです。外で、髪の毛を浮かしたり立てたり巻き上げた人をみると、「あの人… 2006-02-03 僕は、オブジェクトもthisもサッパリ理解できなかった 雑記/備忘 「『常識』というよりは『理解の基盤』と『説明の方法』」に挙げた4つの問いかけのなかで、 メソッド内で使える「this って何?」と聞かれたら…。 これはなんか異質でしょう。thisは、僕自身の記憶に残っている例なんだよね。(以下、愚痴口調の文体。)「犬…

    2006-02-03
    rawwell
    rawwell 2008/10/02
    "今の僕は(またかよ)、メッセージ・パッシングというメタファーは便利だし、役に立つと思っている(ほんとだよ)。でも、なんか擬人化されて、class A 内で発生する呼び出しb.hoge() を「aさんがbさんに『hoge』という命令
  • 2008-10-01 - 兼雑記 ■[Program] デバッガとスレッドとイベント

    実行パスが一つしか無くて、ユーザやらネットワークやら、外部とのインタラクションもブロッキングして読んで問題ないようなプログラムならいいんですが、まぁなんかそうもいかないことも多く、そういう時はスレッドやら select/epoll やら使ってごにょごにょしてるわけです。でまぁ、あろはさんのとこのコメント欄を荒らさせてもらったんですが、まぁデバッガに欲しいスレッドやらイベントサポートの話。なんとなくもやもや思ってることを適当にまとめてみます。 まずまだマシなスレッドの方。まぁ適当に 100 スレッドくらいのスレッドプールの中の一つのスレッドが SEGV したとする。さあデバッガの出番。とりあえず適当に現在のスレッドの値を調べてみたところ、なんかおかしな値が入ってたとします。でまぁ、シングルスレッドでバグが無いとしたら、レースコンディションです。でそいう時にとりあえず、 thread appl

    2008-10-01 - 兼雑記 ■[Program] デバッガとスレッドとイベント
    rawwell
    rawwell 2008/10/01
    "まぁ適当に 100 スレッドくらいのスレッドプールの中の一つのスレッドが SEGV したとする。さあデバッガの出番。とりあえず適当に現在のスレッドの値を調べてみたところ、なんかおかしな値が入ってたとします。でまぁ、