May 13, 2012
On 5/13/12 4:13 AM, Andrei Alexandrescu wrote:
> On 5/11/12 10:38 PM, Ary Manzana wrote:
>> Add a binarySearch(range, object) method that does all of that?
>>
>> I mean, I don't want to write more than a single line of code to do a
>> binarySearch...
>
> assumeSorted(range).contains(object)
>
> is still one line, safer, and IMHO more self-explanatory.
>
> Andrei

Ok. When more people start saying that they can't find a binarySearch method... will you change your mind? :-)

(but let's first wait until that moment comes)
May 13, 2012
On Sun, May 13, 2012 at 07:34:19AM +0700, Ary Manzana wrote:
> On 5/13/12 4:13 AM, Andrei Alexandrescu wrote:
> >On 5/11/12 10:38 PM, Ary Manzana wrote:
> >>Add a binarySearch(range, object) method that does all of that?
> >>
> >>I mean, I don't want to write more than a single line of code to do a binarySearch...
> >
> >assumeSorted(range).contains(object)
> >
> >is still one line, safer, and IMHO more self-explanatory.
> >
> >Andrei
> 
> Ok. When more people start saying that they can't find a binarySearch method... will you change your mind? :-)
[...]

Things like this just needs to be properly documented. Just because it isn't called "binarySearch" doesn't mean anything. We aren't trying to reinvent C#.


T

-- 
Marketing: the art of convincing people to pay for what they didn't need before which you can't deliver after.
May 13, 2012
Andrei Alexandrescu:

> assumeSorted(range).contains(object)
>
> is still one line, safer, and IMHO more self-explanatory.

It's self-explanatory if the name there contains something like
"binarySearch". Otherwise it is NOT self-explanatory, I can't
assume it will use a binary search.
So it's surely not intuitive.

Bye,
bearophile
May 13, 2012
On Fri, 11 May 2012 22:17:07 +0200, Nick Sabalausky <SeeWebsiteToContactMe@semitwist.com> wrote:

> "Mehrdad" <wfunction@hotmail.com> wrote in message
> news:ynstshvzpaiusjyyoipo@forum.dlang.org...
>> On Friday, 11 May 2012 at 18:21:24 UTC, H. S. Teoh wrote:
>>> Templates are stencils for generating code. There's nothing confusing
>>> about that.
>>
>>
>> "Stencils for generating code"? _This_??! :O
>>
>
> Geez, I think I need a vacation: My mind parsed that as a ternary operator
> expression. Only when it tried to apply semantics did reality snap into
> focus.

What did your mind do to the trigraph?

Reminded me of the WTF operator: ??!??!
May 13, 2012
On Sat, 12 May 2012 08:05:26 +0200, Paulo Pinto <pjmlp@progtools.org> wrote:

˙ʇsod-doʇ ʇou op ǝsɐǝlԀ
˙uʍop-ǝpısdn sı ʇsod ɹnoʎ ǝʞıl sɯǝǝs ʇı ʇnq 'noʎ ɯɹɐlɐ oʇ ʇoN

> Your 'nice to have' features are for my type of
> work 'must have' features, otherwise I could as
> well just use Notepad++.
>
> Having used GUI environments since the early MS-DOS
> days, I don't have any issue with my mouse friend. :)
>
> --
> Paulo
>
> Am 12.05.2012 02:00, schrieb Timon Gehr:
>> On 05/11/2012 07:39 PM, Paulo Pinto wrote:
>>>
>>> The author of a D based PSP emulator just rewrote
>>> the emulator in C#, after being disappointed with D.
>>>
>>> https://github.com/soywiz/cspspemu
>>>
>>> The reasons are listed here,
>>>
>>> https://github.com/soywiz/cspspemu#created-after-4-tries
>>>
>>> --
>>> Paulo
>>
>> Well, those are not reasons for me.
>>
>>  > The lack of a good IDE,
>>
>> Properties of a 'good IDE', as I see it:
>>
>> some essential properties:
>> - starts up instantaneously
>> - uses the screen space efficiently
>> - supports editing text efficiently
>> - accepts keyboard input as given by the user.
>> - reasonable support for auto-indentation
>> - supports searching the code for some text efficiently
>> - keeps all code _readable_, especially the one that has been written
>> recently
>> - pattern recognition based code completion
>>
>> - ... by default!
>>
>> some 'nice to have' properties:
>> - code analysis based code completion
>> - navigate-to-declaration
>> - for those languages that require it: automatic generation of boilerplate.
>> - integrated debugger
>> - useful refactoring tools
>> - visualization of compilation errors (but please don't nag me)
>> - actual support for detecting semantic errors as they happen (extremely
>> difficult to do properly)
>> - any other argument that is commonly used to advertise IDEs
>>
>> - ... _responsive_ on halfway recent hardware!
>>
>> some anti-features:
>> - splash screen
>> - cannot run code if there is no 'project/solution file'
>> - sometimes messes up those files
>> - build fails - restart IDE - build works
>> - fancy GUI
>> - requires pointing device
>> - accidental hit of obscure keyboard combination ...
>> => permanent, extremely annoying configuration change
>> => no way to tell what happened
>> => no undo operation
>> - termination of the debugged program kills the output console
>>
>>
>> As long as IDEs fail to satisfy every single point in the 'essential'
>> category and strive to have all of the stated anti-features, they don't
>> have much value for me anyway.
>>
>>  > the complicated structure of the D language,
>>
>> Cannot really comment on that, I think getting work done in D is simple,
>> and with DMD, just slightly harder than that.
>>
>>  > the horrible compilation times,
>>
>> wat? The so-fast-I-could-not-grab-a-coffee-during-compilation kind of
>> horrible? Otherwise he might have hit a bug there.
>>
>>  > caused that it taked too much time for everything, and made it
>>  > impossible to refactoring the code without days or weeks of work.
>>
>> I'd have to know what kind of refactorings he carried out to be able to
>> comment on this.
May 14, 2012
On 2012-05-11 22:20, Jonathan M Davis wrote:

> That's definitely an example of something that depends on your background.
> std.algorithm.any does _exactly_ what it would do in a functional language.
> How intuitive an API is depends a lot on how much the person writing the API
> thinks like you. It's definitely something to strive for, but the best that you
> can generally do is hit the majority of your target audience. You can never
> hit everyone.
>
> - Jonathan M Davis

This one exists in Ruby as well. But in Ruby the block/lambda is optional. If it's not passed it will return a bool indicating if the collection is empty or not, just as Mehrdad expected.

-- 
/Jacob Carlborg
May 14, 2012
On Saturday, 12 May 2012 at 23:27:15 UTC, Alex Rønne Petersen
wrote:
>
> You know, my project consisting of 130-ish source files and 24.000-ish lines of code compiles from scratch in ~20 seconds on my machine, building one file at a time... I honestly have not managed to come up with a build system for D that is actually slow, if compared to C/C++.

Try using GDC the compiler that can actually produce good code,
or using -inline -release flags.

Debug build (GDC, multi invocation, 3 threads)
real	0m42.452s

Release build (GDC, multi invocation, 3 threads)
real	1m0.140s

Debug build (GDC, single invocation)
real	0m22.151s

Release build (GDC, single invocation)
real	0m54.960s

$ find src/ -name "*.d" | xargs wc -l | tail --lines 1
    46057 total

Cheers, Jakob.
May 14, 2012
On Sunday, 13 May 2012 at 10:08:47 UTC, bearophile wrote:
> Andrei Alexandrescu:
>
>> assumeSorted(range).contains(object)
>>
>> is still one line, safer, and IMHO more self-explanatory.
>
> It's self-explanatory if the name there contains something like
> "binarySearch". Otherwise it is NOT self-explanatory, I can't
> assume it will use a binary search.
> So it's surely not intuitive.
>
> Bye,
> bearophile

100% agree with this.

How anyone can possibly think that using assumeSorted(r).contains(x) to do a binary search is more self-explanatory than just writing binarySearch(r, x) is beyond me. It's mind-boggling.

We have proof that it is not intuitive: the fact that people frequently ask how to do a binary search in std.algorithm. If it was intuitive, they wouldn't need to ask. If it was self-explanatory, it wouldn't need to be explicitly mentioned in the documentation. Needing documentation is precisely the opposite of self-explanatory.

Andrei, you are a reasonable person. What evidence would it take to convince you that this design for doing binary searches is bad?
May 14, 2012
On Mon, 14 May 2012 12:01:06 +0200, Peter Alexander <peter.alexander.au@gmail.com> wrote:

> On Sunday, 13 May 2012 at 10:08:47 UTC, bearophile wrote:
>> Andrei Alexandrescu:
>>
>>> assumeSorted(range).contains(object)
>>>
>>> is still one line, safer, and IMHO more self-explanatory.
>>
>> It's self-explanatory if the name there contains something like
>> "binarySearch". Otherwise it is NOT self-explanatory, I can't
>> assume it will use a binary search.
>> So it's surely not intuitive.
>>
>> Bye,
>> bearophile
>
> 100% agree with this.
>
> How anyone can possibly think that using assumeSorted(r).contains(x) to do a binary search is more self-explanatory than just writing binarySearch(r, x) is beyond me. It's mind-boggling.

It is not intuitive, I agree. It is, however, documenting. You're not
calling binarySearch on any old array, you assume it is sorted, *then*
search it.

Perhaps it would be better to have a binarySearch function, which can
only take a SortedRange, and gives an explanatory error message when used
with a NonSortedRange.
May 15, 2012
On Monday, 14 May 2012 at 10:31:47 UTC, Simen Kjaeraas wrote:
> On Mon, 14 May 2012 12:01:06 +0200, Peter Alexander <peter.alexander.au@gmail.com> wrote:
>
>> On Sunday, 13 May 2012 at 10:08:47 UTC, bearophile wrote:
>>> Andrei Alexandrescu:
>>>
>>>> assumeSorted(range).contains(object)
>>>>
>>>> is still one line, safer, and IMHO more self-explanatory.
>>>
>>> It's self-explanatory if the name there contains something like
>>> "binarySearch". Otherwise it is NOT self-explanatory, I can't
>>> assume it will use a binary search.
>>> So it's surely not intuitive.
>>>
>>> Bye,
>>> bearophile
>>
>> 100% agree with this.
>>
>> How anyone can possibly think that using assumeSorted(r).contains(x) to do a binary search is more self-explanatory than just writing binarySearch(r, x) is beyond me. It's mind-boggling.
>
> It is not intuitive, I agree. It is, however, documenting. You're not
> calling binarySearch on any old array, you assume it is sorted, *then*
> search it.
>
> Perhaps it would be better to have a binarySearch function, which can
> only take a SortedRange, and gives an explanatory error message when used
> with a NonSortedRange.

How about users who don't know what binary search is. binary search is an intuitive concept for people who have good programming experience but assumeSorted(r).contains(x) is more intuitive to higher level users. see how many searches you get with binary search on google and how many with contains and sorted. I'm not a developer, I do quantum chemistry and write based on formulas and algorithms in papers, not on libraries. I would prefer people to write code in more general concepts so it's easier for me to understand and learn. And if you know binary search, it's not that much harder to change your style to assumeSorted(r).contains(x); in comparison, to a newbie learning binary search. Also having multiple ways of doing the same thing makes usage more confusing, so it should be avoided unless really needed.
So in short, I support that Andrei aims for larger audience.