View mode: basic / threaded / horizontal-split · Log in · Help
August 29, 2009
OT: What's your favorite codeline?
What's your favorite line of D code?

My one is
Application.Run();

And yours?

------------------------------------------------------------------------------
PS: Check out my D-IDE at http://www.alexanderbothe.com/?id=27
August 29, 2009
Re: OT: What's your favorite codeline?
Sat, 29 Aug 2009 11:14:15 -0400, A Bothe thusly wrote:

> What's your favorite line of D code?
> 
> My one is
> Application.Run();
> 
> And yours?

foreach(Problem p; World.problems) find_answer_to(p);

It just always seems to get stuck.
August 29, 2009
Re: OT: What's your favorite codeline?
A Bothe escribió:
> What's your favorite line of D code?
> 
> My one is
> Application.Run();

Isn't that C#? :-)

I think a favorite line of D code should have a feature of D that 
doesn't appear in any other language...
August 29, 2009
Re: OT: What's your favorite codeline?
incognito wrote:

> foreach(Problem p; World.problems) find_answer_to(p);
> 
> It just always seems to get stuck.

... because it doesn't have `World.plan' to its disposal.
August 29, 2009
Re: OT: What's your favorite codeline?
Sat, 29 Aug 2009 13:45:23 -0300, Ary Borenszweig thusly wrote:

> A Bothe escribió:
>> What's your favorite line of D code?
>> 
>> My one is
>> Application.Run();
> 
> Isn't that C#? :-)
> 
> I think a favorite line of D code should have a feature of D that
> doesn't appear in any other language...

I've heard a d guru known as 'downs' is the master of obfuscated one-
liners.
August 29, 2009
Re: OT: What's your favorite codeline?
Manfred_Nowak Wrote:

> incognito wrote:
> 
> > foreach(Problem p; World.problems) find_answer_to(p);
> > 
> > It just always seems to get stuck.
> 
> ... because it doesn't have `World.plan' to its disposal.

You are lacking a world context, cultural semantics, a problem solver, and a very very large pool of random. Maybe an abstract country factory.
August 30, 2009
Re: OT: What's your favorite codeline?
language_fan wrote:
> Sat, 29 Aug 2009 13:45:23 -0300, Ary Borenszweig thusly wrote:
> 
>> A Bothe escribió:
>>> What's your favorite line of D code?
>>>
>>> My one is
>>> Application.Run();
>> Isn't that C#? :-)
>>
>> I think a favorite line of D code should have a feature of D that
>> doesn't appear in any other language...
> 
> I've heard a d guru known as 'downs' is the master of obfuscated one-
> liners.

Well I wouldn't call myself a 'guru' .. 'mutilator', mebbe :)

That being said, here's the results of a quick grep of my #d log for memorable lines


<downs>       Bignum!(To - From)* slice(int From, int To)() { return cast(Bignum!(To - From)*) ((cast(Type*) this) + From); }

<downs>     struct ZipIterator(A, B) { A a; B b; int length() { return min(a.length, b.length); } Stuple!(typeof(a[0]), typeof(b[0])) opIndex(T...)(T t) { return stuple(a[t], b[t]); } int opApply(C)(C callable) { for (int x = 0; x < length; ++x) { static if (is(typeof(callable(x, a[x], b[x])))) { if (auto res = callable(x, a[x], b[x])) return res; } else { if (auto res = callable(a[x], b[x])) return res; } } return 0; } }

<downs>     class Lévy : LSystem!(8) {
<downs>       mixin(LSysFunc("X -> +X--X+ / step"));

<downs>     Ret!(T[$-1]) delegate(Param!(T[$-1])[T.length - 1 .. $]) bind(T...)(T params) { struct Stuff { T data; Ret!(T[$-1]) call(Param!(T[$-1])[T.length - 1 .. $] rest) { return data[$-1](data[0 .. $-1], rest); } } auto res = new Stuff; foreach (id, value; params) res.data[id] = value; return &res.call; }

<downs>         prettyprint(rand%640, rand%480, Center, rgb(col), Fill = rgb(hsv((col.h + 128) % 255, col.s, col.v)), Format("[size ", rand() % 12 + 8, "] Don't worry, be happy! [/size]"));

<downs>     foo.betweens("src=\"", "\"") /select/ (string s) { return s.find(criteria) != -1; }

<downs>     "/proc/cpuinfo".read().castLike("").between("cpu MHz", "\n").between(": ", "")

<downs>     auto videocon = ctx.getStreams().first(WHERE!("?.codec.codec_type == CodecType.Video")).codec;
August 30, 2009
Re: OT: What's your favorite codeline?
A Bothe wrote:
> What's your favorite line of D code?

I like my recent:

c.resFunc = cast(void 
function(void*))(*cast(void***)proto.resources[origResIdx].init().ptr)[
	Command.Type.ResAcquire == c.type ? 1 : 2
];

Sure, it's 3 lines, but still one statement and if I were downs, that 
would *be* one line ;D


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode
September 01, 2009
Re: OT: What's your favorite codeline?
downs wrote:
> <downs>     foo.betweens("src=\"", "\"") /select/ (string s) { return s.find(criteria) != -1; }

Heh, I love that infix expression syntax. Too abd it ends up with a 
completely useless wrapper struct & 2 function calls, but hopefully LDC 
can inline that out.

> <downs>     auto videocon = ctx.getStreams().first(WHERE!("?.codec.codec_type == CodecType.Video")).codec;

Heh, going LINQ on us, now?
September 02, 2009
Re: OT: What's your favorite codeline?
Robert Fraser wrote:
> downs wrote:
>> <downs>     foo.betweens("src=\"", "\"") /select/ (string s) { return
>> s.find(criteria) != -1; }
> 
> Heh, I love that infix expression syntax. Too abd it ends up with a
> completely useless wrapper struct & 2 function calls, but hopefully LDC
> can inline that out.
> 

I'm 90% sure it can.

[update] Actually, I just tried and LDC compiles a simple /select/ test to plain, inlined code.
[update2] GDC doesn't.
[update3] For that matter, neither does DMD.

LDC is really shaping up to be the best D compiler out there. It already is on Unix (imho). Now if only they can get win32 exception support to work ..

>> <downs>     auto videocon =
>> ctx.getStreams().first(WHERE!("?.codec.codec_type ==
>> CodecType.Video")).codec;
> 
> Heh, going LINQ on us, now?

I _was_ thinking of that :) Could have used ex!() but WHERE is a little denser.

(for comparison: ex!("c -> c.codec.codec_type == CodecType.Video") )
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home