Message 1 of 13
Coding style: What do you think is better?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have 4 rules that do exactly the same thing. Just out of curiosity I would like to know what you think is the best code snippet? Should the code be as short as possible and what about readability?
Snippet 1:
Dim view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view")
If (view Is Nothing) Then Return
view.DrawingCurves.Cast(Of DrawingCurve).Where(Function(c) c.EdgeType = DrawingEdgeTypeEnum.kBendDownEdge Or c.EdgeType = DrawingEdgeTypeEnum.kBendUpEdge).ToList().ForEach(Function(c) view.Parent.DrawingNotes.BendNotes.Add(c))
Snippet 2:
Dim view As DrawingView = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kDrawingViewFilter,
"Select a drawing view")
If (view Is Nothing) Then Return
view.DrawingCurves.Cast(Of DrawingCurve).
Where(Function(c) c.EdgeType = DrawingEdgeTypeEnum.kBendDownEdge Or
c.EdgeType = DrawingEdgeTypeEnum.kBendUpEdge).ToList().
ForEach(Function(c) view.Parent.DrawingNotes.BendNotes.Add(c))
Snippet 3:
Dim view As DrawingView = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kDrawingViewFilter,
"Select a drawing view")
If (view Is Nothing) Then Return
Dim bendCurves = view.DrawingCurves.Cast(Of DrawingCurve).
Where(Function(curve) curve.EdgeType = DrawingEdgeTypeEnum.kBendDownEdge Or
curve.EdgeType = DrawingEdgeTypeEnum.kBendUpEdge).ToList()
Dim bendNotes = view.Parent.DrawingNotes.BendNotes
For Each curve As DrawingCurve In bendCurves
bendNotes.Add(curve)
Next
Snippet 4:
' Let the user select the view that he/she wants to update.
Dim commandManager As CommandManager = ThisApplication.CommandManager
Dim view As DrawingView = commandManager.Pick(
SelectionFilterEnum.kDrawingViewFilter,
"Select a drawing view")
' Check if the user selected a view.
If (view Is Nothing) Then
' If not stop the rule.
Return
End If
' Create a list of all bend cures
Dim bendCUrves As List(Of DrawingCurve)
bendCUrves = New List(Of DrawingCurve)
For Each curve As DrawingCurve In view.DrawingCurves
If (curve.EdgeType = DrawingEdgeTypeEnum.kBendDownEdge) Then
bendCUrves.Add(curve)
End If
If (curve.EdgeType = DrawingEdgeTypeEnum.kBendUpEdge) Then
bendCUrves.Add(curve)
End If
Next
' Add bend notes to all sheets.
Dim sheet As Sheet = view.Parent
Dim bendNotes = sheet.DrawingNotes.BendNotes
For Each curve As DrawingCurve In bendCUrves
bendNotes.Add(curve)
Next
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com