<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Coding style: What do you  think is better? in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11261345#M139743</link>
    <description>&lt;P&gt;I'd likely be between 2 and 3. I'm familiar with Linq now and enjoy using it but I'm by no means proficient with it. So snippet 3 is more likely something I'd normally write. I've been trying to add more comments to my code in general, mostly to help myself in the future since I'm the only one coding for Inventor around my place.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jun 2022 15:34:01 GMT</pubDate>
    <dc:creator>pball</dc:creator>
    <dc:date>2022-06-27T15:34:01Z</dc:date>
    <item>
      <title>Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11254897#M139655</link>
      <description>&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;Snippet 1:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;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))&lt;/LI-CODE&gt;
&lt;P&gt;Snippet 2:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;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))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Snippet 3:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;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&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Snippet 4:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;' 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&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 20:00:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11254897#M139655</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2022-06-23T20:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11254909#M139657</link>
      <description>&lt;P&gt;By the way, this rule will generate all bend notes. More info on my blog post "&lt;A href="http://www.hjalte.nl/53-automatically-generate-bend-notes" target="_blank" rel="noopener"&gt;Automatically generate bend notes&lt;/A&gt;"&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 20:07:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11254909#M139657</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2022-06-23T20:07:03Z</dc:date>
    </item>
    <item>
      <title>Betreff: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255081#M139660</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i prefer Snippet 4, because has Comment.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And this is very good Thing, for yourself, and for other &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@7B4B80143EBEB4F250CEEC82342F6CA1/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 21:38:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255081#M139660</guid>
      <dc:creator>florian_wenzel</dc:creator>
      <dc:date>2022-06-23T21:38:36Z</dc:date>
    </item>
    <item>
      <title>Betreff: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255157#M139663</link>
      <description>&lt;P&gt;I agree that comments can be very useful. But if you ask me the code should make itself clear. Consider snippet 1 and add comments. Something like this.&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;' Let the user select the view that he/she wants to update.&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;view&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingView&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;CommandManager&lt;/SPAN&gt;.&lt;SPAN&gt;Pick&lt;/SPAN&gt;(&lt;SPAN&gt;SelectionFilterEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kDrawingViewFilter&lt;/SPAN&gt;, &lt;SPAN&gt;"Select a drawing view"&lt;/SPAN&gt;)
&lt;SPAN&gt;' Check if the user selected a view. If not stop the rule.&lt;/SPAN&gt;
&lt;SPAN&gt;If&lt;/SPAN&gt; (&lt;SPAN&gt;view&lt;/SPAN&gt; &lt;SPAN&gt;Is&lt;/SPAN&gt; &lt;SPAN&gt;Nothing&lt;/SPAN&gt;) &lt;SPAN&gt;Then&lt;/SPAN&gt; &lt;SPAN&gt;Return&lt;/SPAN&gt;
&lt;SPAN&gt;' Create a list of all bend cures and add bend notes to all sheets.&lt;/SPAN&gt;
&lt;SPAN&gt;view&lt;/SPAN&gt;.&lt;SPAN&gt;DrawingCurves&lt;/SPAN&gt;.&lt;SPAN&gt;Cast&lt;/SPAN&gt;(&lt;SPAN&gt;Of&lt;/SPAN&gt; &lt;SPAN&gt;DrawingCurve&lt;/SPAN&gt;).&lt;SPAN&gt;Where&lt;/SPAN&gt;(&lt;SPAN&gt;Function&lt;/SPAN&gt;(&lt;SPAN&gt;c&lt;/SPAN&gt;) &lt;SPAN&gt;c&lt;/SPAN&gt;.&lt;SPAN&gt;EdgeType&lt;/SPAN&gt; = &lt;SPAN&gt;DrawingEdgeTypeEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kBendDownEdge&lt;/SPAN&gt; &lt;SPAN&gt;Or&lt;/SPAN&gt; &lt;SPAN&gt;c&lt;/SPAN&gt;.&lt;SPAN&gt;EdgeType&lt;/SPAN&gt; = &lt;SPAN&gt;DrawingEdgeTypeEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kBendUpEdge&lt;/SPAN&gt;).&lt;SPAN&gt;ToList&lt;/SPAN&gt;().&lt;SPAN&gt;ForEach&lt;/SPAN&gt;(&lt;SPAN&gt;Function&lt;/SPAN&gt;(&lt;SPAN&gt;c&lt;/SPAN&gt;) &lt;SPAN&gt;view&lt;/SPAN&gt;.&lt;SPAN&gt;Parent&lt;/SPAN&gt;.&lt;SPAN&gt;DrawingNotes&lt;/SPAN&gt;.&lt;SPAN&gt;BendNotes&lt;/SPAN&gt;.&lt;SPAN&gt;Add&lt;/SPAN&gt;(&lt;SPAN&gt;c&lt;/SPAN&gt;))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Even with comments, it's hard to read. &lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 22:24:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255157#M139663</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2022-06-23T22:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255735#M139669</link>
      <description>&lt;P&gt;All of them are useful and readable for me. Which of them is the best, depends on reason and who is the consumer of this snippet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I prefer to split collecting the objects and do some action on them. Because often I need more complex action then one line of code (error handling, logging, comments, etc.) (=&amp;gt; Snippets 3, 4)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know how familiar with LINQ are members of this forum. If they want to modify or reuse the snippet, it can be little bit confusing for them. (=&amp;gt; Snippet 4)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Snippet 1 is very compressed form and it is suitable for some internal functions in addins or other "closed" code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Snippet 2 is nice example how to use LINQ for simple task, but as I mentioned above, it can be hard to modify this code for many of non-advanced users.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 06:56:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255735#M139669</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2022-06-24T06:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255748#M139670</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;If the code is intended to be modified or transferred to different people, for me snippet 4 is the best with or without comments.&lt;/P&gt;&lt;P&gt;The other excerpts are more difficult to read, especially for someone who didn't write it, and when you come back to work on it 6 months later, it's also more difficult to remember what you had chosen earlier.&lt;/P&gt;&lt;P&gt;It's just my personal opinion.&lt;/P&gt;&lt;P&gt;Vincent.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 07:02:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255748#M139670</guid>
      <dc:creator>vpeuvion</dc:creator>
      <dc:date>2022-06-24T07:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255897#M139671</link>
      <description>&lt;P&gt;For me its a close call between 2 and 3. Concise and clear what happens. Code explains itself so no comments are required imo.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since you're using LINQ already you might as well go all the way. So snippet 2 will win.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While being the same as snippet 1 it's alot more readable due to the formatting. If not using iLogic I would create a method for checking the edgetype and the adding of the bendnote to add some logging / error handling.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I agree with Michael Navara that for non-advanced users snippet 4 wins. For me it's just too much unnecessary typing &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 08:12:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11255897#M139671</guid>
      <dc:creator>basautomationservices</dc:creator>
      <dc:date>2022-06-24T08:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11256376#M139681</link>
      <description>&lt;P&gt;I'd go with Snippet 3, because I personally prefer a more verbose style than something like Snippet 2. I like to have each "task" have it's own section in code. The main benefit is when I come back to it 6 months later, it's easier for me to tell what the code does.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Snippet 4 is good for beginners but as a general rule code should be understandable without comments, and I think #2 and #3 are fairly easy to understand. If I do put in comments I tend to put them at the end of a line of code, not before a block. That way I can avoid them if I don't need them, but they are there if I do.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 12:27:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11256376#M139681</guid>
      <dc:creator>Zach.Stauffer</dc:creator>
      <dc:date>2022-06-24T12:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11257189#M139694</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Personally, I don’t think snippet 1 is good in any situation. It is too compressed to read. My personal guild line is that&lt;/SPAN&gt; a line of code should never be longer than 100 characters and a function should never be longer than what fits on the screen. (However, I find myself often in situations where functions are too long.) That is also why I think snippet 2 is better than 1.&lt;/P&gt;
&lt;P&gt;But Using the foreach function from LINQ is not something I do often. Most of the time I have multiple lines of code in a foreach loop and I don’t think you should use multiple lines of code in a LINQ function. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I think snippet 3 is the best if I expect that my code will only be read by someone with some coding experience. But I agree with @&lt;SPAN&gt;&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1104556" target="_blank"&gt;Michael.Navara&lt;/A&gt;&lt;/SPAN&gt; &lt;SPAN&gt;that on this forum we often need to explain a little bit more. And maybe then snippet 4 is then the best. But then again I agree with wit @&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10337235" target="_blank"&gt;basautomationservices&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt; f&lt;/SPAN&gt;&lt;SPAN&gt;or me it's just too much unnecessary typing&lt;/SPAN&gt;. And I don’t think that LINQ code is that hard to read.&lt;/P&gt;
&lt;P&gt;Anyway, I guess we are all more on less on the same page. Thank you for your comments.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 19:37:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11257189#M139694</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2022-06-24T19:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11260331#M139720</link>
      <description>&lt;P&gt;I vote for 3 or 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4 would be the best because it has an explanation. That helps the user to understand a bit about what is going on.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2022 08:18:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11260331#M139720</guid>
      <dc:creator>tomislav.peran</dc:creator>
      <dc:date>2022-06-27T08:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11260770#M139728</link>
      <description>&lt;P&gt;I would choose for snippet 4. Writing code is not my profession, so I would not compact it. I use blank lines to separate associated lines of code (dim &amp;amp; set combo's) and use (short) comments as much as I can.&amp;nbsp;&lt;BR /&gt;I would however create a single line if-statement for the check if the user selected a view.&lt;BR /&gt;I would create an if-else-statement instead of the two if-end if statements for the curves.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2022 12:10:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11260770#M139728</guid>
      <dc:creator>_dscholtes_</dc:creator>
      <dc:date>2022-06-27T12:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11261345#M139743</link>
      <description>&lt;P&gt;I'd likely be between 2 and 3. I'm familiar with Linq now and enjoy using it but I'm by no means proficient with it. So snippet 3 is more likely something I'd normally write. I've been trying to add more comments to my code in general, mostly to help myself in the future since I'm the only one coding for Inventor around my place.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2022 15:34:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11261345#M139743</guid>
      <dc:creator>pball</dc:creator>
      <dc:date>2022-06-27T15:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Coding style: What do you  think is better?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11264336#M139791</link>
      <description>&lt;P&gt;I like the first part of Snippet 1, and the last half of Snippet 3 about the best.&amp;nbsp; The Pick method can just be a 1 liner, because it's not overly long.&amp;nbsp; The check for Nothing can also just be a 1 liner right after that, instead of a 3 line block.&amp;nbsp; But I would prefer to split that really long last part of Snippet 1 into at least 2-3 parts as is done in Snippet 3.&amp;nbsp; Comments are OK if the code is complicated to wrap your mind around or hard to tell what's going on if you were to read again a year later, or someone else may be inheriting your code after you have moved on.&amp;nbsp; I like a good marriage between somewhat condensed, and yet still easy enough for some random mid-level, part time programmer to be able to follow what's going on later.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 16:01:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/coding-style-what-do-you-think-is-better/m-p/11264336#M139791</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-06-28T16:01:10Z</dc:date>
    </item>
  </channel>
</rss>

