|
Yes - and in the TreeView example if the TreeNode only makes sense in a treeview then there should be a Create factory in TreeView and no public constructor.
|
|
|
|
|
Sorry I am not sure if you were being sarcastic or not?...
I don't agree with this, that also means that you cannot inherit from it.
Kris
|
|
|
|
|
A good point. This is harder than it looks
|
|
|
|
|
Hmm, at first look it seems a bit like Captain obvious to the rescue, but it's a good list (that I fail frequently to follow and therefore it can be assumed that others do aswell)
and I don't understand the mass of downvotes, so allow me to compensate a bit.
|
|
|
|
|
It was originally written about 12 years ago - but I have had a total reversal on some points so edited it accordingly.
Thanks for the feedback
|
|
|
|
|
I need help in VB6 with one my projects !
Sub Main()
Const PhysicalSize As Integer = 2500
Dim Inventory(PhysicalSize - 1) As InventoryItem, LogicalSize As Integer
' 1. Load the data from the Inventory File into the array
LoadInventory Inventory, LogicalSize, PhysicalSize
' 2. Process Discontinued Inventory
ProcessDiscontinuedInventory Inventory, LogicalSize
' 3. Process New Inventory
ProcessNewInventory Inventory, LogicalSize
' 4. Process Discounts
ProcessDiscounts Inventory, LogicalSize
' 5. Save the data in the array to the Inventory File
SaveInventory Inventory, LogicalSize
End Sub ' End Main
'_____________________________________________________________
'=============================================================
' LoadInventory
' Purpose:
Sub LoadInventory(ByRef Inventory() As InventoryItem, _
ByRef LogicalSize As Integer, _
ByVal PhysicalSize As Integer)
Open App.Path & "/Inventory.csv" For Input As #1
LogicalSize = 0
Do While Not (EOF(1)) And LogicalSize < PhysicalSize
With Inventory(LogicalSize)
Input #1, .PartNumber
Input #1, .Description
Input #1, .ISBN
Input #1, .Author
Input #1, .Edition
Input #1, .SellingPrice
Input #1, .OnHand
Input #1, .OnOrder
End With
LogicalSize = LogicalSize + 1
Loop
Close #1
End Sub ' End LoadInventory
'_____________________________________________________________
'=============================================================
' SaveInventory
' Purpose:
Sub SaveInventory(ByRef Inventory() As InventoryItem, _
ByVal LogicalSize As Integer)
Dim Index As Integer
Open App.Path & "/Inventory_Out.csv" For Output As #1
For Index = 0 To LogicalSize - 1
With Inventory(Index)
Write #1, .PartNumber, _
.Description, _
.ISBN, _
.Author, _
.Edition, _
.SellingPrice, _
.OnHand, _
.OnOrder
End With
Next
Close #1
End Sub ' End SaveInventory
'_____________________________________________________________
'=============================================================
' ProcessDiscontinuedInventory
' STUDENT_TODO
' Purpose:
Sub ProcessDiscontinuedInventory(ByRef Inventory() As InventoryItem, _
ByRef LogicalSize As Integer)
Dim FoundPosition As Integer
Dim DiscontinuedPartNumber As Long
Dim Index As Integer
Dim DeleteItem As Integer
Dim FoundItem As Integer
Open App.Path & "\Returns.csv" For Output As #1
Open App.Path & "\DiscontinuedInventory.csv" For Output As #2
Index = 0
FoundPosition = FindPartNumber(Inventory, LogicalSize, DeleteItem, FoundPosition) < -- I GET A ERROR OVER HERE SAYIN EXPECTED FUNCTION OR VARIABLE NAME !! and the rest of the code where im calling a function!
If Inventory(FoundItem).OnHand > 0 Then
Write #1, Inventory(Index).Author, Inventory(Index).Description, Inventory(Index).Edition, _
Inventory(Index).ISBN, Inventory(Index).OnHand, Inventory(Index).OnOrder, _
Inventory(Index).PartNumber, Inventory(Index).SellingPrice
DeleteItem = OrderedDelete(Inventory, LogicalSize, DeleteItem)
End If
Close #1
Close #2
End Sub ' End ProcessDiscontinuedInventory
'_____________________________________________________________
'=============================================================
' ProcessNewInventory
' STUDENT_TODO
' Purpose:
Sub ProcessNewInventory(ByRef Inventory() As InventoryItem, _
ByRef LogicalSize As Integer)
Dim FoundPosition As Integer
Dim NewInventory As InventoryItem
Dim Index As Integer
Dim InsertItem As Integer
Index = 0
Open App.Path & "\NewInventory.csv" For Output As #1
Open App.Path & "\DuplicatePartNumbers.csv" For Output As #2
FoundPosition = FindPartNumber(Inventory, LogicalSizem, SearchPartNumber, FoundPosition)
If FoundNumber > 0 Then
Write #2, Inventory.PartNumber, Inventory.Description, Inventory.ISBN, _
Inventory.Author, Inventory.Edition, Inventory.SellingPrice
Else
InsertItem = OrderedInsert(Inventory, LogicalSize, InsertItem)
End If
Close #1
Close #2
End Sub ' End ProcessNewInventory
'_____________________________________________________________
'=============================================================
' ProcessDiscounts
' STUDENT_TODO
' Purpose:
Sub ProcessDiscounts(ByRef Inventory() As InventoryItem, _
ByVal LogicalSize As Integer)
Dim FoundPosition As Integer
Dim PartNumber As Long, SellingPrice As Currency
Open App.Path & "\Discounts.csv" For Output As #1
Open App.Path & "\FailedDiscounts.csv" For Output As #2
FoundPosition = FindPartNumber(Inventory, LogicalSize, PartNumber, FoundPosition)
If FoundPosition > 0 Then
Write #2, Inventory.PartNumber, Inventory.SellingPrice
End If
End Sub ' End ProcessDiscount
|
|
|
|
|
I think the comment ' STUDENT_TODO pretty much covers my response.
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
A programming book that all programmers should read is Code Complete by MS Press. It shows many pitfalls, and way around them. It also shows the best practices to create code in an open architecture way that minimizes code changes as specs change.
|
|
|
|
|
|
|
You asked, could someone understand what your program does if all but the comments were removed?
Yes, because at that point it wouldn't do anything.
Mike
|
|
|
|
|
|
As I see it there are three types of comment.
Firstly you've got "how" comments that explain what the code does. In general, I'm finding (with more modern languages in particular), that the "how" comments are becoming less relevant, as code layout, variable/procedure naming, etc. can show the "how" quite well by themselves.
The second type of comments are the "why's". Recording why a particular piece of code was written, why a certain condition is checked. I've found in maintaining code that it's usually a straight-foward process to find where a procedure is causing a problem. Quite often though, the code was deliberate and now no-one that knows why that code was written. Even a reference to a business requirement, or a functional spec chapter would be a help.
Finally we get to the "who's". Who made the change (name or at least department). This is mainly a fallback when trying to find the "why's".
I've found that software has a substantially longer lifetime than any associated documentation, and without the "why" fixing a small problem in one area of an application can cause down-stream processes to fail.
Of course, with full regression suites and sufficient time/money to run the end-to-end tests this wouldn't be a problem, but I don't think many of us will have seen that with legacy code.
|
|
|
|
|
garyknights wrote:
The second type of comments are the "why's". Recording why a particular piece of code was written, why a certain condition is checked. I've found in maintaining code that it's usually a straight-foward process to find where a procedure is causing a problem. Quite often though, the code was deliberate and now no-one that knows why that code was written.
I fully agree. Having just finished a maintenance contract, and having done a lot of maintenance over the years, I would say that this is the biggest single failing in code commenting among developers. I try to make a habit of providing "why" comments with my own code - if only for myself when I have to look back at it in a year's time. Even then I often have to scratch my head!
Kevin
|
|
|
|
|
Those "secrets" are mostly all cosmetic. You can and you will see programmers following all of these and still fail on many fronts. Programming is a science, not an art.
It is my believing that just like in any fields, there are "naturals" which get it right without much efforts because it is common sense for them. About the only thing they need is willpower and experience.
There are exceptions to this, but I think it holds true for the majority of "successfull" programmers.
Please note that having good social skills, good contacts and the proverbial "being at the right place at the right moment" don't hurt either.
Sébastien
Intelligence shared is intelligence squared.
Homepage : http://www.slorion.webhop.org
|
|
|
|
|
I agree. The "seven secrets" deal mostly with coding style. We all know successful programmers who could care less about style. Not to diminish it's importance, but style really only helps with maintenance and reuse. I write embedded software for the automotive industry, and there is one big key to success here - process. Call this my not-so-secret secret to success.
Our process goes something like this (you may recognize this as the classic "V" diagram):
1. Requirements - know what your software should do before you start coding.
2. Design - Translate the requirements into an architecture or structure which can meet the requirements, given the system constraints.
3. Implementation - The fun part that we all live for (coding).
4. Verification - Testing our code, does it meet the requirements? This should be done by someone other than the software creator. If the requirements are unclear, two people might interpret them differently.
5. Issue tracking / change management - We find the majority of problems come from late changes to the requirements, A.K.A. creeping elegance. This takes discipline to know when there's real value in a change or when it's not worth the risk.
Sure it helps to be a "natural". Maybe a process is just common sense, but given a good process, the only difference between a "natural" and a mear mortal is their level of productivity, not their success.
Tom
|
|
|
|
|
While the process you mention is good and wildly known (but not necessarily wildly used mind you), it merely ensures that the black box you designed works correctly and meets requirements. It tells nothing about the quality of the design and implementation. Also, it supposes that initial design and implementation will be right, which certainly is not always the case. All in all, the V diagram is very basic and is the least one can do. While iterative processes offer some more flexibility, they do not state anything about the design and implementation quality either.
Sébastien
Intelligence shared is intelligence squared.
Homepage : http://www.slorion.webhop.org
|
|
|
|
|
Sébastien Lorion wrote:
While the process you mention is good and wildly known (but not necessarily wildly used mind you), ...
Sébastien,
Did you really mean wildly or widely? Interesting twist that I’m sure applies to some programmers. To be pragmatic, my employer doesn’t rate my performance on the quality of my design and implementation, rather whether my deliverables are there on time and meet their requirements.
The fact that the “V diagram is very basic and is the least one can do” yet it is not “widely used” is the exact reason I brought it up. Too many of us rely on add-hoc processes and heroic last minute efforts to get products out the door. A disciplined design methodology, although common sense to us, is the first thing we abandon when things get tight,
Certainly, the “V diagram” must be iterative. I prefer to think of it more as a spiral passing through the quadrants of specification, design, implementation and test towards the center. With each revolution the changes become smaller until you reach your target.
I don’t want to downplay the importance of good design and implementation practices. One way to promote them is through peer reviews.
Tom
|
|
|
|
|
LOL, yes I meant widely, but looking at it, it's a pretty fun typo
What you are stating about your employer is sad to hear as I know it's the rule, not the exception. Call me idealistic if you will (some do), but quality should be a part of the equation. Not the only criteria, but it should be considered to its right importance. The problem : who is going to judge the quality ?
Sébastien
Intelligence shared is intelligence squared.
Homepage : http://www.slorion.webhop.org
|
|
|
|
|
Quality is judged in the maintenace phase. Or to be more precise the lack of quality!
I have seen examples of deliverables produced extremely fast. Initial bussiness perspective, wow we can make money here delivering faster and chaeper.
Then maintenance kicked in. Far more time and money was spent to correct all lack of quality in the original program. At that stage, and only just then, the management understood the need for quality. Well atleast to the level that lack of quality isn't bad, as long as it keeps proffitable.
cheers,
Paul
|
|
|
|
|
Tom Pruett wrote:
Not to diminish it's importance, but style really only helps with maintenance and reuse.
But those are not unimportant tasks!
Kevin
|
|
|
|
|
Sébastien Lorion wrote:
Those "secrets" are mostly all cosmetic. You can and you will see programmers following all of these and still fail on many fronts.
That's true. But they're still important things to get right. It's just that they're not all there is. But the title of the article is misleading as it suggests that these are the key to successful programming, rather than being part of the requirements.
Sébastien Lorion wrote:
It is my believing that just like in any fields, there are "naturals" which get it right without much efforts because it is common sense for them. About the only thing they need is willpower and experience.
I get the impression that, while there will always be a handful of programmers who are naturally way better than everyone else, in most cases successful programming is down to attitude rather than ability. A lot of programmers know better but are just sloppy. But maybe that attitude of being sloppy or not is a natural characteristic.
I don't think I'm especially great at programming - probably fairly average, in fact. But I just try hard to follow the recommended practices of whatever language I'm using, have consideration for my fellow developers who must maintain my code and so on.
Sébastien Lorion wrote:
Please note that having good social skills, good contacts and the proverbial "being at the right place at the right moment" don't hurt either.
You bet! Never seems to happen to me though.
Kevin
|
|
|
|
|
I pretty much completely disagree with point #2. Code should be self-documenting. It should be written in such a way that you dont *need* comments to understand what's going on. A good litmus test is if an intelligent non-programmer can get the gist of what's going on by reading your uncommented code, you've done a good job of writing it.
One my #1 ways of recognizing poor coders is by the volume of comments they add. It seems like newbie coders comment a lot and more experienced coders produce elegant, readable code that doesn't require a lot of comments.
|
|
|
|
|
This quickly devolves into "if I can understand it when I wrote it, it's commented enough". Fine for you today, not so fine six months from now when you (or somebody else) go back into that obscure routine.
Try reading a complex algorithm's code with "self-commenting code" and you'll see what I mean.
|
|
|
|
|
rondalescott wrote:
I pretty much completely disagree with point #2. Code should be self-documenting. It should be written in such a way that you dont *need* comments to understand what's going on. A good litmus test is if an intelligent non-programmer can get the gist of what's going on by reading your uncommented code, you've done a good job of writing it.
Good comments, tell you why something is being done and not what is being done. With 90% of code, you should be able to tell what is happening by reading the code. Why something is being done (a certain way) is what you need to comment. This makes it easier when you come back to code later.
rondalescott wrote:
One my #1 ways of recognizing poor coders is by the volume of comments they add. It seems like newbie coders comment a lot and more experienced coders produce elegant, readable code that doesn't require a lot of comments.
Again, it depends on the kind of comments. If you have a lot of
// Increment count
nCount++
type comments, the I'd agree - but comments stating why are very important.
Michael
'Logic, my dear Zoe, merely enables one to be wrong with authority.' - The Doctor: The Wheel in Space
|
|
|
|
|