Good observations Rick. Joe's puzzle was very open ended, and the point probably was to find out how other folks define elegance. I commented before to Tom, about how regular expressions were very powerful, but often hard to read.

The solution presented by myself and Anthony, is definitely easier to read, doesn't require instantiation and would run very quickly. Given the task at hand the speed difference between a solution like mine or Anthony's and one like Tom's or Marlon's would be negligible. Either solution could be put into a udf -- which would be my choice to make the code reuseable.

I once wrote a piece of code that tried to determine if their was overlap between two shifts (meaning work shifts. day shift, swing shift, graveyard... that kind of shift). The code I wrote, worked but was about 15 or 20 lines and contained lots of if then logic. My friend and co-worker looked at the problem and said, "I think that could be shorter" he wrote a udf that did the same thing in TWO lines of code. Man... did I feel stupid. His solution was far shorter, *definitely* more clever and I think a bit more elegant.

In this case I think I'd have to agree that creating an object with a method that did just this would be overkill. A udf would be perfect (imo). There's often a struggle in the little company I work for as to when oop goes too far, and it's something I often think about. In this case I can't think of any other methods that would be in that url object, so an object with only one method (imo) should just be a udf.

I dunno... those are just some thoughts I had after reading last nights responses this morning. Joe, where are you in this, buddy? This is your thread (and a good one I think), what do you think? What was your solution? :)

Chris

[EMAIL PROTECTED] wrote:
I think you hit the nail on the head - "elegance" is definitely subjective.

The request didn't specify methodology to be used, if it had to be easy to read or maintain, what version of CF had to be used, or even if it had to be a one-liner. It was pretty much open-ended with the requirements of the characteristics of the URL and the variable scope to pull the value from.
So since Joe sent out the e-mail, wouldn't he would be the one defining 
"elegance".  :)

Rick...


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Daniel Eben 
Elmore
Sent: Wednesday, September 13, 2006 9:16 PM
To: 'Dallas/Fort Worth ColdFusion User Group Mailing List'
Subject: RE: [DFW CFUG] Brain Teaser

So elegant means: without branching, instantiation, or mappings? I wonder
what an elegant application would look like then. Would all the code be in
one giant template? ;)

My component would look quite different than that. I wasn't attempting to
provide the code, just the idea, because I was confused/shocked at what the
community was proposing.

No I'm not a manager and I wasn't picking on your code specifically. I just
grabbed the latest email.

Let's hear back from the others.

-Daniel Elmore



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Marlon Moyer
Sent: Wednesday, September 13, 2006 8:59 PM
To: Dallas/Fort Worth ColdFusion User Group Mailing List
Subject: Re: [DFW CFUG] Brain Teaser

Yes, this is my idea of elegant.  It's self contained, doesn't take up much
space, and functions correctly and quickly without a lot of branching,
instantiation, or mappings, etc. What you described below is a good, simplified flow of the overall process. Unfortunately you left off the implementation. Are you by chance a manager?


<cfcomponent hint="I am a url object and provide related functionality for
parsing different parts of urls">

<cfset variables.instance = structnew()/>
<cfset variables.instance.the_url = ""/>

<cffunction name="init">
   <cfargument name="the_url" type="string" required="true"/>
   <cfset variables.instance.the_url = arguments.the_url/ >
   <cfreturn this/>
</cffunction>

<cffunction name="getVar" returntype="string">
   <cfargument name="var_name" required="true"/>
<cfset var the_value = ""/> <cftry>
      <cfset the_value =
listgetat(rereplace(variables.instance.the_url,"[(?|&)]*pageNum=(\d*)","#chr
(10)#\1#chr(10)#","all"),2,"#chr(10)#")>
<cfcatch type="any"> <!--- The variable must not have been in the url --->
        <cfset the_value = ""/>
      </cfcatch>
      <cfreturn the_value/>
</cffunction>
</cfcomponent>
USAGE:

<cfset objURL =
createObject("components.url_manager").init(cgi.http_referer)/>
<cfset myValue = objURL.getVar("pageNum")/>



On 9/13/06, Daniel Eben Elmore <[EMAIL PROTECTED]> wrote:
Joe asked for an elegant solution. Why does everyone think that means
condensed, bizarre, and hard to read? Is that your idea of "elegant" code?
Would you like to maintain code that looks like this:
listgetat(rereplace(test,"[(?|&)]*pageNum=(\d*)","#chr(10)#\1#chr(10)#","all

"),2,chr(10))

My idea of elegance would involve having a URL object that receives a URL,
parses it, and provides a method, getVar(), from which you can retrieve any
URL variable.

getVar("numPageID")

-Daniel Elmore



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ]
On Behalf Of Marlon Moyer
Sent: Wednesday, September 13, 2006 7:44 PM
To: Dallas/Fort Worth ColdFusion User Group Mailing List
Subject: Re: [DFW CFUG] Brain Teaser

<cfset pagenum =
listgetat(rereplace(test,"[(?|&)]*pageNum=(\d*)","#chr(10)#\1#chr(10)#","all

"),2,chr(10))>
On 9/13/06, Joe Kelly <[EMAIL PROTECTED]> wrote:
I want to see if someone can come up with a more elegant solution to
this problem.

Given:
CGI.HTTP_REFERER will always have a URL variable, "numPageID=xxx"
which is numeric and could be any size number.
The HTTP_REFERER may or may not have other URL variables in any order,
which could be alphanumeric or numeric The current template needs to pull the value of the "numPageID" URL
variable out of the CGI.HTTP_REFERER

I'll show my solution in another post so as not to spoil anyone's view
on this problem, not saying that mine is best, of course!
Thanks,
Joe Kelly

_______________________________________________
Reply to DFWCFUG:
[email protected]
Subscribe/Unsubscribe:
http://lists1.safesecureweb.com/mailman/listinfo/list
List Archives:
http://www.mail-archive.com/list%40list.dfwcfug.org/
http://www.mail-archive.com/list%40dfwcfug.org/
DFWCFUG Sponsors:
www.HostMySite.com
www.teksystems.com/



--
Marlon

_______________________________________________
Reply to DFWCFUG:
  [email protected]
Subscribe/Unsubscribe:
   http://lists1.safesecureweb.com/mailman/listinfo/list
List Archives:
    http://www.mail-archive.com/list%40list.dfwcfug.org/
   http://www.mail-archive.com/list%40dfwcfug.org/
DFWCFUG Sponsors:
  www.HostMySite.com
  www.teksystems.com/




_______________________________________________
Reply to DFWCFUG: [email protected] Subscribe/Unsubscribe: http://lists1.safesecureweb.com/mailman/listinfo/list List Archives: http://www.mail-archive.com/list%40list.dfwcfug.org/ http://www.mail-archive.com/list%40dfwcfug.org/ DFWCFUG Sponsors: www.HostMySite.com www.teksystems.com/

Reply via email to