The code is not quite on Dee. I want to ask if you can somehow arrange the following code through the switch block. I think it would make the code more beautiful. Or tell me any other option, as the same could be written:

if( (command == 1) && openFile(&file, "r") ) { readFile(file, &dataArray, selectSpecifier()); // считали данные из файла if( ! checkData(&dataArray) ) { // проверяем файл writeln("Erroneous file content! "); } 

If anything, you can set an example in C # or C ++, I will try to rewrite your decision on Di.

  • 2
    First, if the code is written in D, then just write, do not fool people into the heading - you have C # in the header, C # and C ++ labels, and the code turns out to be D, which in itself is misleading. Secondly, the similarity of languages ​​does not mean complete identity - say, in the same C # switch, the lines are possible, but in C ++ - not (there may be some other nuances in D) Third, I don’t know of course about D? but in C # you will not rewrite this code on the switch (in any case, in an adequate way). I suspect that in other languages ​​too. Fourthly, from the point of view of branching, the code is quite normal, do not bother - DreamChild
  • Sharp is entirely OO-language, right there is an FP, passing by reference, sending a file descriptor, for some reason I have a feeling that this is just a C branch, not C #. - etki
  • Corrected the description, so as not to mislead people. - Dmitry Bubnenkov

1 answer 1

 switch(1){ import std.file; case 1: auto data = read("файл.txt"); break; default: assert(0); // что-то пошло не так 1 != 1 } 
  • Add a sensible description of the problem or code to your answer so that users can more quickly understand your answer. - Yuri