July 24, 2012
On Tue, 24 Jul 2012 19:02:07 +0200, Russel Winder <russel@winder.org.uk> wrote:

> On Tue, 2012-07-24 at 16:59 +0200, Simen Kjaeraas wrote:
> […]
>> ...which inspired me to write this implementation of fibonacci:
>>
>> T fib(T = int)(int n, T a = 0, T b = 1) {
>>      while ( n-- ) {
>>          TypeTuple!(a,b) = tuple(b, a +b);
>>      }
>>      return a;
>> }
>
> Or possibly better:
>
> long fibonacci ( immutable long n ) {
>   return array ( takeExactly ( recurrence ! ( "a[n-1] + a[n-2]" ) ( 0L , 1L ) , cast ( size_t ) ( n + 1 ) ) ) [ n ] ;
> }
>
> ?

I had to fix things a bit (I have reasons to want the template parameter there):

T fib(T = int)(int n, T a = to!T(0), T b = to!T(1)) {
    while ( n-- ) {
        TypeTuple!(a,b) = tuple(b, a +b);
    }
    return a;
}

Now, try asking each of these for fib!BigInt(1_000_000). :p

-- 
Simen
July 24, 2012
On Tuesday, 24 July 2012 at 06:40:14 UTC, Chris NS wrote:
> On Tuesday, 24 July 2012 at 02:51:44 UTC, H. S. Teoh wrote:
>>
>> Reminds of a certain individual who shall remain unnamed, with whom I argued about why he should *not* implement IPv6 prefix checking by converting the address and prefixes to strings and then using strncmp()... Truly boggles the mind.
>>
>
> I'm reminded of a close friend of mine... once he was asked to review some code, after the sole author had spent a few weeks on it.  I was lucky (?) enough to be in the room to hear him actually say: "That's... cute.  Not *wise* but cute.  Do you remember what functions are?"  I don't recall there being a response.

 I remember seeing some stupid production code that was used at a company I worked at for a while. They were developing jsp pages as part of their training until they got sections hired out (sorta lowest bidder thing, where you would go to them rather than export work over seas).

 The code in question was to convert the input 16byte input from a database into it's GUID id as a text string in java. I don't remember it exactly, but it went something like...

[code]
//remember, java
String toGuid(byte input[16]) {
  String ID = "{";
  if (Integer.toHexString(input[5]).length < 2)
    ID = ID + "0";
  ID = ID + Integer.toHexString(input[5]);
  if (Integer.toHexString(input[6]).length < 2)
    ID = ID + "0";
  ID = ID + Integer.toHexString(input[6]);

//repeat for other 14 bytes, plus adding dashes and ending brace

  return ID;
}
[/code]

 It didn't help the company's Java class that they taught didn't go into low level operations like And and Or and bit shifting. I ended up rewriting it, then they wanted it 'super documented' because they couldn't understand what > were for. (I think there was more documentation commenting low level explanations of what it was doing than actual code).
July 24, 2012
On Tuesday, 24 July 2012 at 22:38:07 UTC, Era Scarecrow wrote:
> documented' because they couldn't understand what > were for.

 Sorry my filter stripped that out. They couldn't understand what << and >> were for.

July 24, 2012
On 7/24/12 6:48 PM, Era Scarecrow wrote:
> On Tuesday, 24 July 2012 at 22:38:07 UTC, Era Scarecrow wrote:
>> documented' because they couldn't understand what > were for.
>
> Sorry my filter stripped that out. They couldn't understand what << and
>  >> were for.

x >>= 2; // if x much greater than 2, assign 2 to it

Andrei

July 25, 2012
On Tuesday, 24 July 2012 at 22:38:07 UTC, Era Scarecrow wrote:
>
> [code]
> //remember, java
> String toGuid(byte input[16]) {
>   String ID = "{";
>   if (Integer.toHexString(input[5]).length < 2)
>     ID = ID + "0";
>   ID = ID + Integer.toHexString(input[5]);
>   if (Integer.toHexString(input[6]).length < 2)
>     ID = ID + "0";
>   ID = ID + Integer.toHexString(input[6]);
>
> //repeat for other 14 bytes, plus adding dashes and ending brace
>
>   return ID;
> }
> [/code]
>

I just died a little inside...

If not for Andrei's little joke, I don't know what I might have done.

Erm, so that I'm not completely off-topic: I know where D has truly gone wrong.  There's just too many damn semi-colons!

July 25, 2012
On Wed, 25 Jul 2012 03:52:28 +0200
"Chris NS" <ibisbasenji@gmail.com> wrote:
> 
> Erm, so that I'm not completely off-topic: I know where D has truly gone wrong.  There's just too many damn semi-colons!
> 

Nah, I know exactly where it went wrong.

Albuquerque.

Shoulda gone left.

July 25, 2012
I've only recently discovered D, and I already think it's great. I mean, where else am I going to find a language that [a] compiles to native code, [b] has classes, [c] has no stupid flat-file #include system, and [d] has a GC? Honestly, I can't think of any others!

I really don't understand it when people yell "no more syntax!!!" though. Someone in this thread suggested using the ? operator to denote "nullable", and someone else objected to additional syntax. Personally I'm in favour of new syntax. One syntax addition that'd be really helpful is something that'd let me shorten "a != null ? a : b" to something like "a??b". Sort of an in-line "orelse". You could even chain them - e.g. "a??b??c". Of course, it'd have to work with nullable types (when null), integers (0), bools (false), and empty or uninitialised strings.

I reckon no pointers or references should be allowed null unless specified as such. That's one thing they even got wrong in .NET. Alternatively, to avoid breaking new code, use some kind of suffix to denote non-nullable.

I'd also like to see native support for embedded XML, like VB.NET has. Of course, it'd be next to useless without LINQ, and that'd require first-class support for iterators (see the YIELD keyword in C# and VB.NET). Then again, iterators are bloody awesome anyway in their own right, LINQ or no LINQ. D should have iterators.

Incidentally, does D have any real RTTI, or are we still in CPP-land on that?
1 2 3 4 5 6 7 8 9 10
Next ›   Last »