View mode: basic / threaded / horizontal-split · Log in · Help
April 07, 2012
Input from a newbie
Hello D community! :-)

I was looking for a sane, object-oriented, 
possible-to-go-low-level programming language, so I decided to 
give D a try today.

Here's some feedback on the things I had/have trouble with. I 
hope some of this may be valuable for you.

1) First off, I really couldn't figure out were I was supposed to 
post this sort of message.  Apparently there aren't any mailing 
lists (a la Google groups) for D?

2) I couldn't find any good documentation on the build process 
and tools I'm supposed to use. Do you guys use standard 
Makefiles? Do you have your own build system? Would be really 
helpful if that was covered on the website.

3) While your error messages are a lot better than GCCs (gives 
you more context, hints about how the compiler interpreted your 
buggy program, etc) it wouldn't hurt if you made them a bit more 
graphical using colors and markers and such (LLVM like).

4) What's the difference between `... foo(MyObject obj) { ... }` 
and `foo(MyObject* obj)`? What are use cases for explicit 
pointers when passing objects? That's not covered in the 
documentation AFAIT.

5) What's wrong with this program? Is it that `printf` doesn't 
understand D strings? If so, how do I use D strings in string 
formatting?

import std.stdio;

string foo() { return "foobar"; }

int main() {
  printf("%s\n", foo());
  return 0;
}


Jonas
April 07, 2012
Re: Input from a newbie
On Saturday, 7 April 2012 at 22:21:36 UTC, Jonas wrote:
> Hello D community! :-)
>
> I was looking for a sane, object-oriented, 
> possible-to-go-low-level programming language, so I decided to 
> give D a try today.

good choice, welcome! ;-)

> 4) What's the difference between `... foo(MyObject obj) { ... 
> }` and `foo(MyObject* obj)`? What are use cases for explicit 
> pointers when passing objects? That's not covered in the 
> documentation AFAIT.

You normally don't need pointers. Objects are always passed by
reference. So MyObject* obj would be redundant.

> 5) What's wrong with this program? Is it that `printf` doesn't 
> understand D strings? If so, how do I use D strings in string 
> formatting?
>
> import std.stdio;
>
> string foo() { return "foobar"; }
>
> int main() {
>   printf("%s\n", foo());
>   return 0;
> }

printf is a C function which expects 0-terminated strings. D's
strings are variable-length arrays and not zero-terminated.

Don't use printf. Try using writef instead. Same arguments.

Stefan
April 07, 2012
Re: Input from a newbie
Jonas:

> Hello D community! :-)

Welcome here.


> I was looking for a sane, object-oriented, 
> possible-to-go-low-level programming language, so I decided to 
> give D a try today.

D supports OOP well enough, but template-based programming seems 
equally fit or even more. Also keep in mind that the D GC is not 
so efficient, so avoid creating too many small objects, as you do 
in Java.


> 1) First off, I really couldn't figure out were I was supposed 
> to post this sort of message.

This is the right place.


> 2) I couldn't find any good documentation on the build process 
> and tools I'm supposed to use. Do you guys use standard 
> Makefiles? Do you have your own build system? Would be really 
> helpful if that was covered on the website.

One tool fit for not huge programs is rdmd. I use "bud" still, 
but it's getting obsolete.


> 3) While your error messages are a lot better than GCCs (gives 
> you more context, hints about how the compiler interpreted your 
> buggy program, etc) it wouldn't hurt if you made them a bit 
> more graphical using colors and markers and such (LLVM like).

I don't think Walter will love this idea.


> 4) What's the difference between `... foo(MyObject obj) { ... 
> }` and `foo(MyObject* obj)`?

If obj is a class instance, then the first syntax is the one you 
will find in D programs.


> What are use cases for explicit pointers when passing objects? 
> That's not covered in the documentation AFAIT.

It's not documented because you don't use explicit pointers to 
pass objects around. Pointers are used to pass structs around 
when you don't want to copy them.


> 5) What's wrong with this program? Is it that `printf` doesn't 
> understand D strings? If so, how do I use D strings in string 
> formatting?

Use write, writef, writeln, writefln for D strings and for 
several other D data structures.

Take a look here for many small examples programs in D to do many 
different kind of things (not all of them are up to date or fully 
correct, but most of them are good, and the wrong ones are being 
fixed one after the other):
http://rosettacode.org/wiki/Category:D

Bye,
bearophile
April 08, 2012
Re: Input from a newbie
On Saturday, 7 April 2012 at 22:21:36 UTC, Jonas wrote:
>
> 5) What's wrong with this program? Is it that `printf` doesn't 
> understand D strings? If so, how do I use D strings in string 
> formatting?
>
> import std.stdio;
>
> string foo() { return "foobar"; }
>
> int main() {
>   printf("%s\n", foo());
>   return 0;
> }
>

You can use toStringz() from std.string to convert D strings to 
null terminated strings when you need to interface with C 
functions. But in this case, writeln() would be the simplest 
solution. It would be only:

writeln(foo());

Instead of:

printf("%s\n", toStringz(foo()));

I'm a newbie in D too, so correct me if there is anything wrong.
April 08, 2012
Re: Input from a newbie
On Sunday, April 08, 2012 00:21:35 Jonas wrote:
> 1) First off, I really couldn't figure out were I was supposed to
> post this sort of message.  Apparently there aren't any mailing
> lists (a la Google groups) for D?

These are both newsgroups and mailing lists, and there's forum software on top 
of it as well.

Newsgroups: http://www.digitalmars.com/NewsGroup.html
Mailing Lists: http://lists.puremagic.com/cgi-bin/mailman/listinfo
Forum: http://forum.dlang.org/

You can pick which interface you want to use. They're all the same thing. It's 
just a question of how you access it. But no, it's not quite like google 
groups.

- Jonathan M Davis
April 09, 2012
Re: Input from a newbie
On Saturday, 7 April 2012 at 22:42:19 UTC, Stefan wrote:
> printf is a C function which expects 0-terminated strings. D's
> strings are variable-length arrays and not zero-terminated.
>
> Don't use printf. Try using writef instead. Same arguments.

http://d.puremagic.com/issues/show_bug.cgi?id=7872
April 09, 2012
Re: Input from a newbie
On Saturday, 7 April 2012 at 23:58:20 UTC, bearophile wrote:
> Jonas:
>
>> Hello D community! :-)
>
> Welcome here.
>
>
>> I was looking for a sane, object-oriented, 
>> possible-to-go-low-level programming language, so I decided to 
>> give D a try today.
>
> D supports OOP well enough, but template-based programming 
> seems equally fit or even more. Also keep in mind that the D GC 
> is not so efficient, so avoid creating too many small objects, 
> as you do in Java.
>
>
>> 1) First off, I really couldn't figure out were I was supposed 
>> to post this sort of message.
>
> This is the right place.
>
>
>> 2) I couldn't find any good documentation on the build process 
>> and tools I'm supposed to use. Do you guys use standard 
>> Makefiles? Do you have your own build system? Would be really 
>> helpful if that was covered on the website.
>
> One tool fit for not huge programs is rdmd. I use "bud" still, 
> but it's getting obsolete.
>
>
>> 3) While your error messages are a lot better than GCCs (gives 
>> you more context, hints about how the compiler interpreted 
>> your buggy program, etc) it wouldn't hurt if you made them a 
>> bit more graphical using colors and markers and such (LLVM 
>> like).
>
> I don't think Walter will love this idea.

Could you please elaborate on this a bit more? What's the problem 
with helpful compiler messages?

>> What are use cases for explicit pointers when passing objects? 
>> That's not covered in the documentation AFAIT.
>
> It's not documented because you don't use explicit pointers to 
> pass objects around. Pointers are used to pass structs around 
> when you don't want to copy them.

Thanks for the explanation!

> Take a look here for many small examples programs in D to do 
> many different kind of things (not all of them are up to date 
> or fully correct, but most of them are good, and the wrong ones 
> are being fixed one after the other):
> http://rosettacode.org/wiki/Category:D

That looks great, thanks, although it's a bit cluttered with all 
those languages ;-)
April 09, 2012
Re: Input from a newbie
On Sunday, 8 April 2012 at 03:55:33 UTC, Jonathan M Davis wrote:
> On Sunday, April 08, 2012 00:21:35 Jonas wrote:
>> 1) First off, I really couldn't figure out were I was supposed 
>> to
>> post this sort of message.  Apparently there aren't any mailing
>> lists (a la Google groups) for D?
>
> These are both newsgroups and mailing lists, and there's forum 
> software on top
> of it as well.
>
> Newsgroups: http://www.digitalmars.com/NewsGroup.html
> Mailing Lists: 
> http://lists.puremagic.com/cgi-bin/mailman/listinfo
> Forum: http://forum.dlang.org/
>
> You can pick which interface you want to use. They're all the 
> same thing. It's
> just a question of how you access it. But no, it's not quite 
> like google
> groups.

Thanks Jonathan, the mailman interface is what I looked for.
April 09, 2012
Re: Input from a newbie
On 4/9/12, Jonas <jonas@lophus.org> wrote:
> On Saturday, 7 April 2012 at 22:42:19 UTC, Stefan wrote:
>> printf is a C function which expects 0-terminated strings. D's
>> strings are variable-length arrays and not zero-terminated.
>>
>> Don't use printf. Try using writef instead. Same arguments.
>
> http://d.puremagic.com/issues/show_bug.cgi?id=7872

I don't think the compiler can warn about this. Isn't printf one of
those unsafe C variadic functions? Someone correct me if I'm wrong.
April 09, 2012
Re: Input from a newbie
On 04/09/2012 05:39 PM, Andrej Mitrovic wrote:
> I don't think the compiler can warn about this. Isn't printf one of
> those unsafe C variadic functions? Someone correct me if I'm wrong.

The GCC C compiler proves you wrong :) They have warnings. I guess it's 
a hack (because printf really doesn't belong into the compiler) but that 
doesn't matter.  What matters is user-friendliness.
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home