Pages

Friday, July 22, 2011

Understanding C++ STL Internals

Found the below resources quite useful for understanding STL internals:
May not be up-to-date but [SGI Stl Programmer's Guide](http://www.sgi.com/tech/stl/stl_introduction.html). It has a good conceptual overview of the STL library. 
Source code navigation: 
I've used the [Free Evaluation Source Insight Code Browser](http://www.sourceinsight.com/eval.html) which allows to jump all around the source code from sgi's stl code. 
Alternatively you can try out [LXR](http://lxr.linux.no/+trees), [Doxygen](http://www.stack.nl/~dimitri/doxygen), [Ctags](http://ctags.sourceforge.net). 

Videos: 
[Going Deep into STL with Stephen Lavavej](http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-2-of-n) 
[Inside STL with Stepan Lavavej](http://channel9.msdn.com/shows/Going+Deep/VC-10-Stephan-T-Lavavej-and-Damien-Watkins-Inside-STL) 
[C++0x Features in VC10](http://blogs.msdn.com/b/vcblog/archive/2009/02/03/rvalue-references-c-0x-features-in-vc10-part-2.aspx) 

See Also: 
[C++ Templates - The Complete Guide by Nicolai Josuttis](http://www.josuttis.com/tmplbook/) 
[C++ Template Meta-Programming - Concepts, Tools and Techniques](http://www.boostpro.com/mplbook)
[Inside the C++ Object Model by Stanley Lippman](http://my.safaribooksonline.com/book/programming/cplusplus/0201834545)

Friday, July 8, 2011

Understanding DOM with DOMC source code browsing

Understanding DOM with DOMC (a C implementation of DOM - minus a few features)

Use the Source Luke!!

Note: DOMC is freely available under the MIT License
  1. Download the DOMC source code (200 KB)
  2. Download the libmba helper code (200 KB)
  3. cd domc/src
  4. ctags *
  5. vim domc.h
  6. Navigate through the struct Document, Node, NodeList etc to understand the utter simplicity of the DOM C implementation
domc.h and node.c are THE most important files.

Core implementation

a) DOM_Node is THE struct to understand and it's very very simple
It's recursively defined - a tree is a node containing other nodes/nodelists.
1) Fixed part - common to all nodes from document to attribute
struct DOM_Node {
    DOM_String *nodeName;
    DOM_String *nodeValue;
    unsigned short nodeType;             //Used as selector on union of variable parts below
  
    //Pointers to other Nodes
    DOM_Node *parentNode;
    DOM_NodeList *childNodes;

    DOM_Node *firstChild;
    DOM_Node *lastChild;
    DOM_Node *previousSibling;
    DOM_Node *nextSibling;

    DOM_NamedNodeMap *attributes;
    DOM_Document *ownerDocument;
[...]
2) Variable part - DOMNode.nodeType above selects between document vs element vs attribute vs processing-instruction
union {
        struct {
            DOM_DocumentType *doctype;
            DOM_Element *documentElement;
                        DOM_DocumentView *document;
                        DOM_AbstractView *defaultView;
                        DOM_Node *commonParent;
                        DOM_String *version;
                        DOM_String *encoding;
                        int standalone;
        } Document;
        struct {
            DOM_String *tagName;
        } Element;
        struct {
            DOM_String *name;
            int specified;
            DOM_String *value;
                        DOM_Element *ownerElement;
        } Attr;
        struct { // small code stripped out for clarity } DocumentType;
        struct { // small code stripped out for clarity } CharacterData;
        struct { // small code stripped out for clarity } Notation;
        struct { // small code stripped out for clarity } Entity;
        struct { // small code stripped out for clarity } ProcessingInstruction;
    } u;
b) DOM_NodeList itself is a doubly-linked list with head/tail pointers
struct NodeEntry { struct Node *data; NodeEntry *before, *after; };
struct DOM_NodeList { NodeEntry *first, *last; DOM_NodeList *list; }
Don't need the documentation at all but here it is anyway :
DOMC - A C Implementation of DOM docs

Tuesday, November 30, 2010

Learning Python Coding Techniques and Idioms by Browsing Python Source Code


Study the standard libraries source code for good examples of Python coding.


Using Pythonic Idioms and Style:
Definition of "Pythonic" here
Presentations:
How to Write Pythonic" code by Christopher Arndt
Presentation on "Code Like a Pythonista: Idiomatic Python" by David Goodger
Presentation on "Code Like a Pythonista: Idiomatic Python" (Crunchy Remix) by Jeff Hinrich 

Bruce Eckel's community contributed book: Python 3 - Patterns & Idioms


See Also:
My blog on Learning Python

Source Code Browsing Tools

Source Insight 3.5 Download Instructions
Source Insight Video 
ack -- better than grep, a power search tool for programmers
Source-Navigator
Splint Home Page (C code static checking)
Browse by Query
scan.coverity.com : Accelerating Open Source Quality  

Eclipse:
Eclipse IDE with C++ CDT
Eclipse CDT 4.0 Webinar
This webinar will walk through all of CDT's features from new project creation, code editing, and source navigation, to build and debug with a special focus on what's new in CDT 4.0.  
Eclipse CDT - Webinar on Developing C/C++ Applications
Eclipse C++ Development Howtos, Tutorials, Guides and Videos

NetBeans:
NetBeans IDE with C++ support
NetBeans - Development with C and C++ Learning Trail

Global

GNU GLOBAL source code tag system
idutils - Summary [Savannah]
taglist.vim - Source code browser (supports C-C++, java, perl, python, tcl, sql, php, etc) vim
Using Global with Vim Tutorial

CScope

cbrowser | Get cbrowser at SourceForge.net
VI and VIM editor: Tutorial and advanced features from YoLinux
Vim-Cscope tutorial

Ctags

Browsing programs with tags - Vim Tips Wiki - a Wikia wiki
Exuberant Ctags
Exuberant Ctags FAQ
VI and VIM editor: Tutorial and advanced features

Doxygen

___CodeProject: 10 Minutes to document your code. Free source code and programming help
__Download details HTML Help Workshop and Documentation
__Graphviz Setup Download
Doxygen (Extensions to doxygen for other languages support)
Doxygen Commenting Commands
Doxygen Projects
Doxygen Quick Reference.pdf (application/pdf Object)
Eclox (plugin integrates Doxygen with Eclipse)
Graphviz
graphviz build notes
MscGen - Wikipedia, the free encyclopedia
Mscgen A Message Sequence Chart Renderer (Call Sequence)
xchm (chm for Unix Linux MacOSx)
chmProcessor: Word/HTML to CHM converter
Doxygen Browser Addin for Visual Studio
Download Doxygen Browser 0.1.3 Beta Free - Softpedia

GCC_XML

__Boost.Python (the C++ Python connection)
__Boost.Python C++ code generator Introduction
__Edison Design Group (C++ Compiler Based Analysis for Tools)
__pyplusplus introduction
__Pyste (Boost C++ code generator) Documentation
__Python C++ language binding
__What is Boost.Python Tutorial
FAQ ___GCC-XML (cpp2xml) - Generate XML description of C++ code
Info on Parsing C++ at nobugs.org - UnUpdated but Useful
pygccxml - Python parser for GCC-XML output
pyste - Boost.Python wrapper generator for GCC-XML
Sourceforge - C++ Python Language Bindings Download
The gccxml Mailing List Archives
The VFiasco Project (with Links on Parsing C++)

Lxr

___SourceForge.net LXR Cross Referencer
__LXR - The Linux Cross Reference (like SourceInsight)

Vim

0scan - Tags based search for any things you might want to find(ctags, buffers etc)
C++ code completion - Vim Tips Wiki
OmniCppComplete - C/C++ omni-completion with ctags database : vim online
Recommended Vim plugins for C coding? - Stack Overflow
SourceCodeObedience - Browse source code easily with cscope, ctags and marks system

Learning by Source Code Browsing Miniaturized Open Source Software

Links:

[Networking]
Tiny Http daemon: thttpd (tiny http web server), apache's httpd at trunk - GitHub
Pion : (Web Analytics Server written in C++ Boost under Boost Open Source license)
Pion binary downloads for Redhat, Ubuntu, OSX and Windows are available at: http://www.atomiclabs.com/pion-web-analytics/download.php
1) Pion Core Platform: Pion Core is an open source software platform for building stream computing (also known as complex event processing) applications.
2) Pion-Net Library:The Pion Network Library (pion-net) is a C++ development library for implementing lightweight HTTP interfaces. (C++ Boost STL Multithreading Asio Networking Library) Download the source code here


ACE:

  • ACE is an open-source framework that provides many components and patterns for developing high-performance, distributed real-time and embedded systems. ACE provides powerful, yet efficient abstractions for sockets, demultiplexing loops, threads, synchronization primitives.

  • TAO (The ACE ORB) is an open-source implementation of a CORBA Object Request Broker (ORB) built using components and patterns in the ACE framework.

  • CIAO (Component Integrated ACE ORB) is an open-source implementation of the CORBA Component Model (CCM) built on top of TAO.

  • DAnCE is an open-source implementation of the Deployment and Configuration standard (D&C) built on top of TAO.



  • Download ACE, TAO and CIAO source code  (Distributed Network Middleware Framework and ORB)

    uIP (Micro implementation of TCP/IP stack)
    Download - uIP source
    Memcached distribute caching: memcached - Google Code, memcached - GitHub



    [STL]
    SGI STL Site and Resources (Design docs, FAQs, Books)
    Download SGI STL source code (C++ Standard Template Library implementation)
    (Related to STL)
    A standard allocator for C++ STL on sourceforge
    Database Template Library - DTL on sourceforge
    DTL docs
    Download DTL source code

    [Other]
    VideoLAN - VLC media player source code
    LXR Cross Referencer  (Online Source code Browser)