Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That sounds easy to check. Can you expand on this, because I don't understand.


Meaning computationally. It would cost a lot of cycles to keep that enabled in production.

It’s only O(n), but if I check that assertion in my binary search function then it might as well have been linear search.


Basically this could be something like this, D based example:

    void process_list(List aList)
    in(aList.isSorted, "List must be sorted!")
    do
    {
    // do something
    }
However the O() cost of calling isSorted() has an impact on overall cost for process_list() on every call, hence why the way contracts are executed is usually configurable in languages that have them available.


its easy as in "simple to implement and execute" but not cheap, because it may require scanning large amounts of memory. You have to visit every list entry.

Whats trivial for a very small list, may be a no-go for gigabyte-sized lists.


Ah I see. That's the bit of the conversation I was trying to head off with "rhetorical" :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: