RE: Line Counter (without Comments)
Over the last couple of days in my free time, I've been working on a modification to the code you guys posted, so it won't count blank lines and lines that were commented out. Here are the results. It looks for these comment types: !--- --- !-- -- /* */ It won't count single comment lines, nor sections of commented code. Also, if you happen to have your end comment tag at the beginning of another line of valid code, that line /will/ be counted. Do you guys see any problems with this code (aside from the mutilation of line wrapped email)? cfdirectory directory=C:\apache2\htdocs\test\testFolder action=list name=mySite filter=* sort=directory recurse=yes cfset totalLines = 0 !---loop over all the files and filter on list of extensions--- cfloop query=mySite cfif type eq file cfif listLen(name, '.') GT 1 AND cfc,cfm,css,html,js CONTAINS listGetAt(name, 2, '.') !---create an array of line items (parse by ascii carriage return and output the name of the file--- cffile action=read file=#directory#\#name# variable=curFile cfset beginComments = !--|\/\* cfset endComments = --|\*\/ cfset relevantLines = 0 cfset skipLine = 0 cfset skipMultiple = 0 cfloop list=#curFile# index=curLine delimiters=#chr(13)##chr(10)# cfif (ReFind(beginComments,curLine) !--- The start of a CFML or HTML comment --- and ReFind(endComments,curLine) !--- The end of a CFML or HTML comment --- and not ReFind([[:print:]]+(!--),curLine)) !--- don't skip lines where the comment is after some code --- or not ReFind([[:graph:]],curLine) !--- skip blank lines --- !--- In this case, we found a single commented line, so skip it --- cfset skipLine = 1 cfelseif ReFind(!--,curLine) and not ReFind([[:graph:]]+(!--),curLine) !--- In this case, we found the beginning of a commented section of code --- cfset skipLine = 1!--- skip this line --- cfset skipMultiple = 1 !--- set a flag to keep skipping lines until I tell you to stop --- cfelseif not skipMultiple !--- this is a normal line of code --- cfset skipLine = 0 /cfif cfif skipMultiple !--- We're in a commented section of code --- cfif ReFind(--,curLine) !--- we found the end of the comment --- cfif ReFind((--)[[:blank:]]*[[:print:]]+,curLine) !--- Don't skip this line if there is other uncommented code on the line (after the end comment tag) --- cfset skipLine = 0 /cfif cfset skipMultiple = 0 !--- remove the 'skip lines' flag --- /cfif /cfif cfif not skipLine cfset relevantLines = relevantLines+1 /cfif /cfloop cfoutput#name#br //cfoutput !---add current file's line count to total--- cfset totalLines = totalLines + relevantLines /cfif /cfif /cfloop !---output line count total--- cfoutput#totalLines#/cfoutput - This transmission may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. A1. ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered
Line Counter (without Comments)
Piggy-backing this off the existing thread: The one script that was shared was great, just one exception, what if you wanted to obtain the lines of actual code rather than code and comments? The script will count each line. TIA! ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253043 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Line Counter (without Comments)
what if you wanted to obtain the lines of actual code rather than code and comments? Then it would be time to use CF_REextract and parse files! ;-) -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253049 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: Line Counter (without Comments)
N, just roll without comments. I mean cmon, you wrote the code, you should remember what it does! Chris -Original Message- From: Claude Schneegans [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 2:56 PM To: CF-Talk Subject: Re: Line Counter (without Comments) what if you wanted to obtain the lines of actual code rather than code and comments? Then it would be time to use CF_REextract and parse files! ;-) -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253052 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: Line Counter (without Comments)
Problem is there are many developers that work with the code. -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 3:15 PM To: CF-Talk Subject: RE: Line Counter (without Comments) N, just roll without comments. I mean cmon, you wrote the code, you should remember what it does! Chris -Original Message- From: Claude Schneegans [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 2:56 PM To: CF-Talk Subject: Re: Line Counter (without Comments) what if you wanted to obtain the lines of actual code rather than code and comments? Then it would be time to use CF_REextract and parse files! ;-) -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253054 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Line Counter (without Comments)
I had a nightmare assignment once to fix two lines of code in a file that had 7800 lines. There were nested tables, inside nested loops, multiple CFiFs, lots of cfif clientID=x and version=y And not one comment anywhere. The project manager had the view that comments only make the file size bigger and therefore slower to load. It took me most of the day to find the lines I had to fix. Just for spite, I put a comment in the code when i finished the task. Cheers Mike Kear Windsor, NSW, Australia Adobe Certified Advanced ColdFusion Developer AFP Webworks http://afpwebworks.com ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month On 9/14/06, Adkins, Randy [EMAIL PROTECTED] wrote: Problem is there are many developers that work with the code. -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 3:15 PM To: CF-Talk Subject: RE: Line Counter (without Comments) N, just roll without comments. I mean cmon, you wrote the code, you should remember what it does! Chris ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253056 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: Line Counter (without Comments)
Oh I agree, I an not dissing the comments, just our client wants an actual line count of code. From a developer stand point, comments are greatly appreciated especially in a team environment. -Original Message- From: Mike Kear [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 3:42 PM To: CF-Talk Subject: Re: Line Counter (without Comments) I had a nightmare assignment once to fix two lines of code in a file that had 7800 lines. There were nested tables, inside nested loops, multiple CFiFs, lots of cfif clientID=x and version=y And not one comment anywhere. The project manager had the view that comments only make the file size bigger and therefore slower to load. It took me most of the day to find the lines I had to fix. Just for spite, I put a comment in the code when i finished the task. Cheers Mike Kear Windsor, NSW, Australia Adobe Certified Advanced ColdFusion Developer AFP Webworks http://afpwebworks.com ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month On 9/14/06, Adkins, Randy [EMAIL PROTECTED] wrote: Problem is there are many developers that work with the code. -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 3:15 PM To: CF-Talk Subject: RE: Line Counter (without Comments) N, just roll without comments. I mean cmon, you wrote the code, you should remember what it does! Chris ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253059 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: Line Counter (without Comments)
I think in a file with 7800 lines, an extra 100 lines worth of comments aren't going to amount to much additional file size. Silly project managers. !//-- andy matthews web developer certified advanced coldfusion programmer ICGLink, Inc. [EMAIL PROTECTED] 615.370.1530 x737 --//- -Original Message- From: Mike Kear [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 2:42 PM To: CF-Talk Subject: Re: Line Counter (without Comments) I had a nightmare assignment once to fix two lines of code in a file that had 7800 lines. There were nested tables, inside nested loops, multiple CFiFs, lots of cfif clientID=x and version=y And not one comment anywhere. The project manager had the view that comments only make the file size bigger and therefore slower to load. It took me most of the day to find the lines I had to fix. Just for spite, I put a comment in the code when i finished the task. Cheers Mike Kear Windsor, NSW, Australia Adobe Certified Advanced ColdFusion Developer AFP Webworks http://afpwebworks.com ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month On 9/14/06, Adkins, Randy [EMAIL PROTECTED] wrote: Problem is there are many developers that work with the code. -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 3:15 PM To: CF-Talk Subject: RE: Line Counter (without Comments) N, just roll without comments. I mean cmon, you wrote the code, you should remember what it does! Chris ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253060 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: Line Counter (without Comments)
Plus cf comments are not shown to the browser and therefore are not part of the final html and therefore don't affect the final filesize. -Original Message- From: Andy Matthews [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 3:52 PM To: CF-Talk Subject: RE: Line Counter (without Comments) I think in a file with 7800 lines, an extra 100 lines worth of comments aren't going to amount to much additional file size. Silly project managers. !//-- andy matthews web developer certified advanced coldfusion programmer ICGLink, Inc. [EMAIL PROTECTED] 615.370.1530 x737 --//- -Original Message- From: Mike Kear [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 2:42 PM To: CF-Talk Subject: Re: Line Counter (without Comments) I had a nightmare assignment once to fix two lines of code in a file that had 7800 lines. There were nested tables, inside nested loops, multiple CFiFs, lots of cfif clientID=x and version=y And not one comment anywhere. The project manager had the view that comments only make the file size bigger and therefore slower to load. It took me most of the day to find the lines I had to fix. Just for spite, I put a comment in the code when i finished the task. Cheers Mike Kear Windsor, NSW, Australia Adobe Certified Advanced ColdFusion Developer AFP Webworks http://afpwebworks.com ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month On 9/14/06, Adkins, Randy [EMAIL PROTECTED] wrote: Problem is there are many developers that work with the code. -Original Message- From: Peterson, Chris [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 3:15 PM To: CF-Talk Subject: RE: Line Counter (without Comments) N, just roll without comments. I mean cmon, you wrote the code, you should remember what it does! Chris ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253063 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Line Counter (without Comments)
The ideal thing would have been to take this big file and break it into smaller bits - cfcs or includes or custom tags, however that wasnt an option apparently. Since the actual work was only a 5 minute job but it took most of the day to do, his decision not to have comments anywhere was an expensive one. I'm assuming that plenty of people before me had done similar work on this file too, so add up all that extra cost as my predecessors and those following me waded through the mud on this file and the absence of comments has probably cost many many times more than the original cost of writing the file did. Cheers Mike Kear Windsor, NSW, Australia Adobe Certified Advanced ColdFusion Developer AFP Webworks http://afpwebworks.com ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month On 9/14/06, Andy Matthews [EMAIL PROTECTED] wrote: I think in a file with 7800 lines, an extra 100 lines worth of comments aren't going to amount to much additional file size. Silly project managers. !//-- andy matthews web developer certified advanced coldfusion programmer ICGLink, Inc. [EMAIL PROTECTED] 615.370.1530 x737 --//- ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253064 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Line Counter (without Comments)
On 9/13/06, Mike Kear [EMAIL PROTECTED] wrote: The ideal thing would have been to take this big file and break it into smaller bits - cfcs or includes or custom tags, however that wasnt an option apparently. Yeah, I like the small bits part, and personally, I roll without comments 'cause my code is self-explanatory. Just kidding but I think the idea is sound. Especially with the hint field of functions, which if you use right, you can generate docs off of, I've heard. :-) That was one of the parts of the PP book I liked, the bit about not wasting time commenting stuff that shouldn't need it, so to speak. But generally I try to write my code so I'll know what's going on by looking at the code, so I avoid things like naming a b c vars, 'cept for very obvious cases. As for the line count, that's really an interesting number. I'd count hand coded HTML as real code, but wouldn't count a DW template's code everywhere it occurred, nor generated files. So a simple regex is going to be tough to write. It's possible, I'm sure, but it would probably be as long as my tragic EOL mishap line of code, and woe is the non-regex-uber-guru working on that, neh? Simple, no. Quite a problem. Plus, for a bonus to cf-talk, I'll recount a story my dad told me about a programmer he hired. Keeping in mind that he himself programmed. My dad would walk around the company, you know, seeing what people were up to, what they're working on, etc.. One person would be watching the line, another working levers, others sweating over a forge or moving huge pallets of stuff hither and yon... And then there was the programmer, staring off into space. It pissed him off that he never knew if he was working or not. :-) LOL I can never do my dad's stories justice, he's got a real flare for 'em, that I find difficult to capture. Practice, I guess. :-) Might take a certain type to find that funny, but I think we've got that type here. Anyways the point is it's hard to measure anything besides how many lines of code you have. 5 is 5. Wow, didn't know that. Doesn't really mean squat, besides what it means. Sheesh. I make a ton of sense when I try, don't I? [= -Denny ~| Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting, up-to-date ColdFusion information by your peers, delivered to your door four times a year. http://www.fusionauthority.com/quarterly Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253090 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4