1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

我真落伍,人家现在都流行D语言了,C语言的升级版本

本帖由 laogui2006-06-13 发布。版面名称:谈天说地

  1. laogui

    laogui Administrator
    管理成员

    注册:
    2005-08-30
    帖子:
    15,216
    赞:
    35
    "It seems to me that most of the "new" programming languages fall into one of two categories: Those from academia with radical new paradigms and those from large corporations with a focus on RAD and the web. Maybe it's time for a new language born out of practical experience implementing compilers." -- Michael
    "Great, just what I need.. another D in programming." -- Segfault
    D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. Special attention is given to the needs of quality assurance, documentation, management, portability and reliability.
    D is statically typed, and compiles direct to native code. It's multiparadigm: supporting imperative, object oriented, and template metaprogramming styles. It's a member of the C syntax family, and its look and feel is very close to C++'s. For a quick feature comparison, see this comparison of D with C, C++, C# and Java.
    It is not governed by a corporate agenda or any overarching theory of programming. The needs and contributions of the D programming community form the direction it goes.
    There are currently two implementations, the Digital Mars DMD package for Win32 and x86 Linux, and the Gnu D package for several platforms, including Mac OS X.
    A large and growing collection of D source code and projects are at dsource. More links to innumerable D wikis, libraries, tools, media articles, etc. are at dlinks.
    This document is available as a pdf, as well as in Japanese and Portugese translations. A Japanese book D Language Perfect Guide is available.
    This is an example D program illustrating some of the capabilities:
    代码:
    #!/usr/bin/dmd -run
    /* sh style script syntax is supported */
    
    /* Hello World in D
       To compile:
         dmd hello.d
       or to optimize:
         dmd -O -inline -release hello.d
    */
    
    import std.stdio;
    
    void main(char[][] args)
    {
        writefln("Hello World, Reloaded");
    
        // auto type inference and built-in foreach
        foreach (argc, argv; args)
        {
            // Object Oriented Programming
            CmdLin cl = new CmdLin(argc, argv);
            // Improved typesafe printf
            writefln(cl.argnum, cl.suffix, " arg: %s", cl.argv);
            // Automatic or explicit memory management
            delete cl;
        }
    
        // Nested structs and classes
        struct specs
        {
            // all members automatically initialized
            int count, allocated;
        }
    
        // Nested functions can refer to outer
        // variables like args
        specs argspecs()
        {
            specs* s = new specs;
            // no need for '->'
            s.count = args.length;		   // get length of array with .length
            s.allocated = typeof(args).sizeof; // built-in native type properties
            foreach (argv; args)
                s.allocated += argv.length * typeof(argv[0]).sizeof;
            return *s;
        }
    
        // built-in string and common string operations
        writefln("argc = %d, " ~ "allocated = %d",
    	argspecs().count, argspecs().allocated);
    }
    
    class CmdLin
    {
        private int _argc;
        private char[] _argv;
    
    public:
        this(int argc, char[] argv)	// constructor
        {
            _argc = argc;
            _argv = argv;
        }
    
        int argnum()
        {
            return _argc + 1;
        }
    
        char[] argv()
        {
            return _argv;
        }
    
        char[] suffix()
        {
            char[] suffix = "th";
            switch (_argc)
            {
              case 0:
                suffix = "st";
                break;
              case 1:
                suffix = "nd";
                break;
              case 2:
                suffix = "rd";
                break;
              default:
    	    break;
            }
            return suffix;
        }
    }
    Note: all D users agree that by downloading and using D, or reading the D specs, they will explicitly identify any claims to intellectual property rights with a copyright or patent notice in any posted or emailed feedback sent to Digital Mars.
     
  2. jcking

    jcking Well-Known Member

    注册:
    2005-08-30
    帖子:
    22,282
    赞:
    70
    PHP:
    #!/usr/bin/dmd -run
    /* sh style script syntax is supported */

    /* Hello World in D
       To compile:
         dmd hello.d
       or to optimize:
         dmd -O -inline -release hello.d
    */

    import std.stdio;

    void main(char[][] args)
    {
        
    writefln("Hello World, Reloaded");

        
    // auto type inference and built-in foreach
        
    foreach (argcargvargs)
        {
            
    // Object Oriented Programming
            
    CmdLin cl = new CmdLin(argcargv);
            
    // Improved typesafe printf
            
    writefln(cl.argnumcl.suffix" arg: %s"cl.argv);
            
    // Automatic or explicit memory management
            
    delete cl;
        }

        
    // Nested structs and classes
        
    struct specs
        
    {
            
    // all members automatically initialized
            
    int countallocated;
        }

        
    // Nested functions can refer to outer
        // variables like args
        
    specs argspecs()
        {
            
    specs= new specs;
            
    // no need for '->'
            
    s.count args.length;           // get length of array with .length
            
    s.allocated typeof(args).sizeof// built-in native type properties
            
    foreach (argvargs)
                
    s.allocated += argv.length typeof(argv[0]).sizeof;
            return *
    s;
        }

        
    // built-in string and common string operations
        
    writefln("argc = %d, " "allocated = %d",
        
    argspecs().countargspecs().allocated);
    }

    class 
    CmdLin
    {
        private 
    int _argc;
        private 
    char[] _argv;

    public:
        
    this(int argcchar[] argv)    // constructor
        
    {
            
    _argc argc;
            
    _argv argv;
        }

        
    int argnum()
        {
            return 
    _argc 1;
        }

        
    char[] argv()
        {
            return 
    _argv;
        }

        
    char[] suffix()
        {
            
    char[] suffix "th";
            switch (
    _argc)
            {
              case 
    0:
                
    suffix "st";
                break;
              case 
    1:
                
    suffix "nd";
                break;
              case 
    2:
                
    suffix "rd";
                break;
              default:
            break;
            }
            return 
    suffix;
        }
    }
     
  3. zmnet

    zmnet Well-Known Member

    注册:
    2006-05-03
    帖子:
    7,809
    赞:
    62
  4. 空气飘飘

    空气飘飘 New Member

    注册:
    2005-12-26
    帖子:
    3,658
    赞:
    33