2015-03-17

Планируя собрать проект на свежеустановленной в виртуалку убунте, набрал

svn clone http://...

"git stat", кстати, тоже частый гость.

немного за rust

  1. Получил прекрасное сообщение об ошибке:
     error: mismatched types:
     expected `&fn(i32, i32) -> i32 {foo::plus}`,
        found `&fn(i32, i32) -> i32 {foo::minus}`
    
     let v: &[&Fn(i32, i32) -> i32] = [&plus, &minus];
    
    На самом деле, там проблема в другом месте -- массив не приведен к срезу ( забыл & перед [), что видно из след. сообщения об ошибке. 
  2. Из примера использования биндингов к Qt
    QString::new7("Cannot load %1.").arg12(&fileName, 0, &QChar::new9(' ' as i8))
    Разные версии функций Qt, отличающиеся типов аргуменов, при генерации биндингов получили индексы. Перегрузка функции по типу аргументов не то чтобы невозможна, но требует некоторой работы -- нужен параметризируемый (generic) трейт ("интерфейс",  аналог class из Хаскеля или protocol из Свифта):
    trait Overload<X> {
     fn call_with(self, arg: X) -> ();
    }
    
    struct Foo;
    
    impl Overload<u8> for Foo {
     fn call_with(self, arg: u8) {  }
    }
    
    impl Overload<i32> for Foo {
     fn call_with(self, arg: i32) {  }
    }
    
    

2015-03-05

Из анонса новой CRT в Visual Studio

...
The "best" example of this maintainability problem could be found in the old implementation of the printf family of functions. The CRT provides 142 different variations of printf, but most of the behavior is the same for all of the functions, so there are a set of common implementation functions that do the bulk of the work. These common implementation functions were all defined in output.c in the CRT sources(1). This 2,696 line file had 223 conditionally compiled regions of code (#ifdef, #else, etc.), over half of which were in a single 1,400 line function. This file was compiled 12 different ways to generate all of the common implementation functions. 
...
We have converted most of the CRT sources to compile as C++, enabling us to replace many ugly C idioms with simpler and more advanced C++ constructs. The publicly callable functions are still declared as C functions, of course (extern "C" in C++), so they can still be called from C. But internally we now take full advantage of the C++ language and its many useful features.
...
Before this refactoring, the sprintf functions, which write formatted data to a character buffer, were implemented by wrapping the result buffer in a temporary FILE object and then deferring to the equivalent fprintf function.