To begin in D coming from Python

JAnderson ask at me.com
Mon Jul 21 23:05:24 PDT 2008


Luis P. Mendes wrote:
> Hi,
> 
> I use to program in Python, but I need some programs to run much faster.  
> So, D seems to be as the best programming language for my needs.
>  
> Still, there's a long way to go because I've never programmed in C.
> 
> To begin with, is version 2 just a developer version or should I start by 
> using it? 
> 
> In Python, lists can have variables, functions, text and others as 
> elements.  As far as I can recall from reading a C book, arrays in C 
> don't have this possibility.  What about it in D?  
> 
> And regarding list comprehensions like li = [elem*2 for elem in li]?  is 
> there something close in D?
> 
> For example, how could I do something like:
> valores = []
> for c in lista_campos: valores.append(getattr(self,c)), so that I can 
> have all the 
> 
> Is there also any construct similar to dictionaries?
> 
> Are there D libraries to access PostgreSQL database or do I have to use 
> C's?
> 
> I don't know about the theoretical issues regarding language development, 
> so documentation with good examples is a must have. Is there something 
> like www.diveintopython.org in the short term horizon?
> 
> These are just some topics I need to know about D.  I'd appreciate some 
> answers.
> 
> 
> Luis

Ok, I assume you might know some of this but I'm going to talk about 
some of the basics.  Also note that I have the barest knowledge about 
python.

D should be faster then Python in the general case.  Its very easy to 
drop down to the bare metal when necessary.  Its a systems language 
after all.

You'll find that you won't always get as concise syntax as python.  I 
don't think that's necessarily a bad thing as it provides extra type 
safely that you don't get in python.  Note: typesafty also means you'll 
need to write less unit checks because the compiler will do a lot of 
that testing for you, which I think is an actual time saver.

Having said that D is certainly easier to write then C and provides 
nicer lists.  Note lists are typesafe as well so you can only put one 
type of thing into them.  That's not a bad thing (in my option) because 
normally you need to know what you are going to pull out in the first place.

Instead of Duck typing you'll need to learn use inheritance and 
polymorphism.  This is yet another form of compiletime/typesafety.

A website you might find useful is the wiki: 
http://prowiki.org/wiki4d/wiki.cgi

-Joel



More information about the Digitalmars-d mailing list