Python Forum
Approach to coding, good/bad
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Approach to coding, good/bad
#21
(Apr-28-2017, 06:03 AM)ndc85430 Wrote: I'm not a big fan of commenting code, because the only thing that tells you what the code does is the code itself (and the tests, of course!) - comments can be misleading (e.g. if they're out of date) and extra noise (I've seen lots of commented out code just left there in projects I've worked on). I much prefer code to be written in a way that makes the intent clear - by using good names and breaking things down into small pieces (like nice, small functions).
This is all very good - unless you have a multi-threaded project. When you have to implement complicated decision-making logic. When you have to account for system limitations or write optimization.

The purpose of the comments - occasionally - is not to explain what have you done, but rather why you've done it that particular way. What are limitations and border conditions.

On the other hand - breaking code in too small fragments may muddle your intents more efficiently that outdated comments.

On an anecdotal side - I was once asked by a code reviewer to explain in comments Linux shortcut syntax.... Naughty
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#22
Comments, good names, tests (manual and automatic), good documentation, and well factored code are all part of the process. They should all be taken into account. Leaving out any piece just brings a weakness to your code.

And opposed to test first programming, I prefer comment first programming. Write out the function signatures and class declarations, but instead of filling them with code, fill them with comments on how things are going to work. Make yourself think through everything that is going to happen, so you can see where the parts aren't going to work with each other. This allows you to fix a lot of problems without ever having to redo any code. It also makes writing the code tremendously easier.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#23
Quote:Make yourself think through everything that is going to happen, so you can see where the parts aren't going to work with each other
I used to like to model in UML for this reason, but haven't had a good UML since Rational Rose became so expensive.
Reply
#24
(Apr-29-2017, 01:26 AM)Larz60+ Wrote:
Quote:Make yourself think through everything that is going to happen, so you can see where the parts aren't going to work with each other
I used to like to model in UML for this reason, but haven't had a good UML since Rational Rose became so expensive.

I have never seen any usefulness in UML for "modeling" (ie, helping coming out with a better design). It's OK to share your ideas with other folks, though.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#25
Quote:I have never seen any usefulness in UML for "modeling" .
Neither did I until I was forced to use it for an application.
I actually feel that the visual aspect of it forced me to think of situations that I wouldn't have thought of otherwise.
It also laid out the database schema in a nice way.
...
But then again, it's been 14 years since I've used it, and I've got along perfectly well without.
Reply
#26
I've found modelling complex databases to be very helpful. I've never modeled anything else, but I can imagine it could be useful for similar reasons.
Reply
#27
(Apr-29-2017, 11:54 AM)Larz60+ Wrote:
Quote:I have never seen any usefulness in UML for "modeling" .
Neither did I until I was forced to use it for an application.
I actually feel that the visual aspect of it forced me to think of situations that I wouldn't have thought of otherwise.
It also laid out the database schema in a nice way.
...
But then again, it's been 14 years since I've used it, and I've got along perfectly well without.

In all the specs I  have seen written using UML "tools", the author thought that the graphics were enough. It even got as bad as a project were the UML designer/architect stated that the DB schema from the tool was cast in concrete and would never change (to the point that we could not open a defect against the model). Of course it lasted about a month until they had to give in and have a first update. In the end in 18 months we had about 40 updates to the data model.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#28
(Apr-29-2017, 03:07 PM)Ofnuts Wrote: In all the specs I have seen written using UML "tools", the author thought that the graphics were enough. It even got as bad as a project were the UML designer/architect stated that the DB schema from the tool was cast in concrete and would never change (to the point that we could not open a defect against the model). Of course it lasted about a month until they had to give in and have a first update. In the end in 18 months we had about 40 updates to the data model.

Any design tool can be used poorly. Out of date comments, incorrect documentation, not putting the time into design, descriptive names leaving out details, and so on. That, in itself, is not a reason to not use that design tool.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to approach pyusb application arch m3atwad151 0 706 Nov-10-2022, 06:11 AM
Last Post: m3atwad151

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020