Jon*_*ker 13
我可以推荐Simon Tatham的拼图系列.这是一系列适用于Windows,OS X和Linux(以及作为Java小程序)的益智游戏(扫雷,数独,十五).这个架构非常简单:有一个前端接口有三个实现(每个平台一个),一个后端接口,每个游戏有一个实现(我给出了三个例子)和一个让它们一起通话的中端,做序列化和其他整洁的东西.
基本上,这是很好的OOP.用C语言写的.很容易做出贡献(我实现了Filling和Range游戏),因为它有很好的文档记录,而且很容易阅读.
Disruptor的代码是典型的,也可以从它为实现现代硬件的极端性能所做的工作中学到很多东西.
值得一读的是Martin Fowler对其架构,技术论文(PDF)和QCon演示的解释.此外,开发人员博客还包含很多好的阅读内容 - 尤其是Mechanical Sympathy Blog,其中教授了许多关于现代CPU和内存如何工作的内容.
我发现清晰简洁的源代码的最好的部分之一是jQuery源代码.无论你是否喜欢Javascript,它都是一个很好的案例,反对"代码作为文档"的拥护者.
有很多评论,但它不是ascii艺术品,你可以看到明确的推理 - 评论让你知道究竟想要实现什么.
一个例子(完整来源):
(function(){
var
// Will speed up references to window, and allows munging its name.
window = this,
// Will speed up references to undefined, and allows munging its name.
undefined,
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$,
jQuery = window.jQuery = window.$ = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
},
// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
// Is it a simple selector
isSimple = /^.[^:#\[\.,]*$/;
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
// Make sure that a selection was provided
selector = selector || document;
// Handle $(DOMElement)
if ( selector.nodeType ) {
this[0] = selector;
this.length = 1;
this.context = selector;
return this;
}
// Handle HTML strings
if ( typeof selector === "string" ) {
// Are we dealing with HTML string or an ID?
var match = quickExpr.exec( selector );
// Verify a match, and that no context was specified for #id
if ( match && (match[1] || !context) ) {
// HANDLE: $(html) -> $(array)
if ( match[1] )
selector = jQuery.clean( [ match[1] ], context );
// HANDLE: $("#id")
else {
var elem = document.getElementById( match[3] );
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem && elem.id != match[3] )
return jQuery().find( selector );
...
Run Code Online (Sandbox Code Playgroud)