Long lines of code and readability

This is great C # code and works great with the right URL. But everything is simply done on the same line, reducing code readability.

Here is the code:

         return new StreamReader(WebRequest.Create(urlName).GetResponse().GetResponseStream()).ReadToEnd();

I'm just curious about the opinions of other developers regarding such a short way to write code.

+3
source share
5 answers

Point it to a well-named method and possibly break it down so that one statute spans a couple of lines. I would also use WebClient:

return new WebClient().DownloadString(urlName);
+5
source

No, this is not a great C # code. You must dispose of StreamReader, so at least there is an instruction using:

using (StreamReader reader = new StreamReader(WebRequest.Create(urlName).GetResponse().GetResponseStream()) {
   return reader.ReadToEnd();
}

, , .

. . :

if (i <= 4) i = 4 - i;

if , if :

if (i <= 4) {
   i = 4 - i;
}

, , , , .

+5

... YUCK.

, , , .

( , ++) , , , , . #, , .

0

In addition to the readability issue, you should use any IDisposble object that you use.

0
source

One statement! = One line, you can improve readability by improving the formatting of your code. Of course, you should not assume that other people use high-resolution monitors.

0
source

Source: https://habr.com/ru/post/1704160/


All Articles