Are you forced to eliminate the syntax breakthrough?

When you encounter an unsatisfactory view of working code, how likely is it to be reorganized? I know that the aesthetics of the code are mostly subjective, but I am very worried about the ugly code and it is difficult to resist the urge to clear it.

I do not like:

Heavy duty investment

AndFinally(AndThenDoThis(DoThis(strVar, 1, DoThat("February"))), FetchValue(0))

More brackets, commas and ampersands than necessary

CType(ctlGrid.DataSource, DataView).RowFilter = "HourlyRate > 100.00"

and consider adding a method (or extension method) to get

ctlGrid.DataView.RowFilter = "HourlyRate > 100.00"

alternately, I would change:

rows = tblEmp.Select("AnnualEarnings > " & dEarnings.ToString & " AND Position = '" & strPosition & "'")

:

rows = tblEmp.Select("AnnualEarnings > ? AND Position = ?", dEarnings, strPosition)

Now this is a bit extreme, but I'll even take a general idiom, for example, by finding the first element in an array and providing it with a method:

row = tblEmps.Select("Position = 'Manager'")(0)

becomes (and, I think, more readable):

row = tblEmps.Select("Position = 'Manager'").First

When I see it, it drives me crazy

frmMain.grdEmployees.colName.Bold = True
frmMain.grdEmployees.colName.Font = "Arial"
frmMain.grdEmployees.colName.BackColor = "lightyellow"

and regarding what is easier for me to read, I get:

With frmMain.grdEmployees.colName
  .Bold = True
  .Font = "Arial"
  .BackColor = "lightyellow"
End With

. , - , .

, . Do not Make Me Think" . , ( -) , , , . , , , .

? "" ? ?

+5
13

- , - .

, , -, . , . , , , .

(, (0) . ) , : . i.addOne(), ++? , "++", , addOne(), . .

, , . , f (x (y (z (q)))) , : , , , , .

+7

, , , . , . - , , , .

.

+14

, , , . , : .

+4

, , - , ...

  • ? , , , , , ? , . ( ), , "" .
  • , ?
  • ? , , .
  • ? , .

, , , , , , , .

, .

+3

" " , , , :

AndFinally (AndThenDoThis
             (DoThis (strVar,
                      1,
                      DoThat("February"))),
            FetchValue(0))

, "" ( ), .

+3

( ), "" . , , . , 10 20 , 30 , , .

, .

+3

:

  • ?
  • - , ?

, "". , , . , , , , , . , - , , .

. " , -", , . - , , , , !

. , . , . , ( ) , , . , , , , ! , , , , ( ) , .

, , . , .

+2

.

, , , , . ? ? .

, , , .

+1

.

0

.

.
firstManagerow = tblEmps.Select("Position = 'Manager'").First

, .

.

rows = tblEmp.Select("AnnualEarnings > " & dEarnings.ToString & " AND Position = '" & strPosition & "'")

0

, resharper .NET-, , .

IDE , . , , , , , . - resharper:).

0

, , , ( ) . , . , , , .

For i As Integer = 0 To tblEmps.Rows.Count - 1
  Console.WriteLine(tblEmps.Rows(i)("Name"))
Next

, i .

0

Only refactoring, if you need to assume that this is a commercial enterprise. For example, an example of using the "Heavy function" function, when debugging is divided into several lines, makes life easier. Getting rid of parentheses is much easier to make mistakes. Yes, it may look better, but good is really not more readable / better. It is more like the style you are used to seeing.

0
source

All Articles