473,773 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Commenting source code is for amateurs

The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF

Nov 21 '05 #1
18 1308
Do you have a question?
"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF

Nov 21 '05 #2
I thank the pot for calling the kettle black as doing so makes
it perfectly clear that only 'professional' sissies use Visual Basic.

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REM OVETHISTEXTmetr omilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF


Nov 21 '05 #3
Bad news Marian - Pros comment their code.

Maybe you should have commented which version was which, then you wouldn't
have mixed up semi-pro and pro versions in your final statement.

"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF

Nov 21 '05 #4
Comments and massive documentation are done in professional software
development... if you don't explain what a function does in comments and
documentation how will you remember what it does after writing another 400
functions? most likely you will forget what 80% of them do by that point and
will need some kind of reference.. and when someone else starts working on
your code also in a team they definatly need reference points to look at
such as comments, markers, and documentation to even begin to understand
what is going on in code especially on a massive scale like 100,000+ lines
of code... so saying comments are useless, pointless, or anything else
similar to that is just stupid. people may think they are "1337" just
because they can read code without comments, but if you had a 100 line
function and had no clue what it did uncommented would you want to step
through it line by line to determine exactly what it does, what it effects
and what it may return? I doubt you would want to waste that time.
"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF

Nov 21 '05 #5
Do you have a question?
"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF

Nov 21 '05 #6
I thank the pot for calling the kettle black as doing so makes
it perfectly clear that only 'professional' sissies use Visual Basic.

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REM OVETHISTEXTmetr omilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF


Nov 21 '05 #7
Bad news Marian - Pros comment their code.

Maybe you should have commented which version was which, then you wouldn't
have mixed up semi-pro and pro versions in your final statement.

"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF

Nov 21 '05 #8
Comments and massive documentation are done in professional software
development... if you don't explain what a function does in comments and
documentation how will you remember what it does after writing another 400
functions? most likely you will forget what 80% of them do by that point and
will need some kind of reference.. and when someone else starts working on
your code also in a team they definatly need reference points to look at
such as comments, markers, and documentation to even begin to understand
what is going on in code especially on a massive scale like 100,000+ lines
of code... so saying comments are useless, pointless, or anything else
similar to that is just stupid. people may think they are "1337" just
because they can read code without comments, but if you had a 100 line
function and had no clue what it did uncommented would you want to step
through it line by line to determine exactly what it does, what it effects
and what it may return? I doubt you would want to waste that time.
"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl...
The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF

Nov 21 '05 #9
Marian,
The pro solution is the same as the semi-pro but without comments
What would this solution be?

'
' Function to count words in a string
'
' Parameters:
' input - string containing words to be counted
'
' Returns:
' The number of words in the string
'
Private Shared Function WordCount(ByVal input As String) As Integer
Static regex As New System.Text.Reg ularExpressions .Regex("\w+")
Return regex.Matches(i nput).Count
End Function
Alternatively I would consider using String.Split, Strings.Split, or
RegEx.Split to split the input into "words" then count the number of
elements returned, especially if there was other processing to do on the
words. Note in VS.NET 2005 (aka Whidbey, due out later in 2005) The comments
preceding the function would be in XML Documentation format so as to show up
in the Object Browser & intellisense.

Something like:

''' <summary>Functi on to count words in a string</summary>
''' <param name="input">st ring containing words to be counted</param>
''' <returns>The number of words in the string</returns>
''' <remarks>
''' Sample function to return the number of words in a string.
''' </remarks>
Private Shared Function WordCount(ByVal input As String) As Integer
...

Hope this helps
Jay
"Marian F." <No****@NoSpam. Net> wrote in message
news:uf******** ******@tk2msftn gp13.phx.gbl... The 12 years old genius function to count english words in a sentence:

' This is my function to count english words in your string
' s is the string with your words to be counted
' Returns an integer as the number of words found
Public Function iCW(ByVal s As String) As Integer
' We start declaring the variable to count words
Dim c As Integer
' This is the variable used in the for next loop
' to check every char in your string s
Dim i As Integer
' Now check all chars in your string s
' Starts with the 1st char, i = 1
' up to last char, s.Length
For i = 1 To s.Length
' check is the char is a space
If Mid(s, i, 1) = " " Then
' if it is a space, increment the word count WordCount
c += 1
' if it is not, then do nothing
End If
' continue to check words until no more
Next
' return the word count, c
' after adding 1 to compensate for the word before the first space
Return c + 1
End Function
The semi-pro solution to count english words in a sentence:

Public Function WordCount(ByVal Text As String) As Long
While InStr(Text, " ") ' remove double spaces
Replace(Text, " ", " ")
End While
If Replace(Text, " ", "") = "" Then Return 0 ' only spaces
Dim WordCount As Long
For i = 1 To Len(Text)
If Mid(s, i, 1) = " " Then WordCount += 1
Next
Return WordCount + 1
End Function

The pro solution is the same as the semi-pro but without comments

MF

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

383
12250
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a poor man's DBMS, a broken email server and various other /application/ servers to try and crack the Internet and IS markets. In the case where they didn't spend their own money to get companies to
46
2496
by: Profetas | last post by:
Hi, I know that this is off topic. but I didn't know where to post. Do you comment your source code while coding or after coding. for example: you write a procedure and after it is working, you'll comment it.
8
1866
by: lallous | last post by:
Hello I've been programming for a number of years, however my commenting style is always different. Sometimes I use something like: /************************ * method .... * comments... *************************/
2
1085
by: RYoung | last post by:
Can someone point me to a reference concerning source code commenting with VB 2005, ala C# commenting? I googled and found alot of links to add-ins and commercial products, but I can't find any info on whether documentation generation is supported with VB 2005 using xml comments. Thanks, Ron
100
4759
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to use comments. Thanks in advance! -- http://www.gotw.ca/resources/clcm.htm for info about ]
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.