- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I confirm seeing this "mariconadas" in Mexico but mostly in 14-year old teenage girls.
/Mexican (at least until we are annexed by the States)
Admin
<FONT face="Courier New" size=2>she told me she was 28! *purges AIM list*</FONT>
Admin
Let's settle for log2 and 6 comparisons. Otherwise, I would have to ask you to prove you can do it in 4 comparisons.
Admin
Actually, O(log n) could also mean 80000 comparisons for 50 states and 126052 comparisons for 500 states (although this numbers would be a WTF in the context of this task)
Admin
I'm not sure how O(log n) gives 80000 for 50 states. Can you elaborate?
Admin
<FONT face="Courier New" size=1><script language="VBScript" runat="server">
Function RenderStates()
Const KEY = "StateStringArray"
Dim sStates, sSelectedState, sSelected
If IsEmpty(Application(KEY)) Then
sStates = Array( _
Array("", "State"), _
Array("AL", "AL" ), _
Array("AK", "AK" ), _
Array("AZ", "AZ" ), _
Array("AR", "AR" ), _
Array("CA", "CA" ), _
Array("CT", "CT" ), _
Array("CO", "CO" ), _
Array("DC", "D.C." ), _
Array("DE", "DE" ), _
Array("FL", "FL" ), _
Array("GA", "GA" ), _
Array("HI", "HI" ), _
Array("ID", "ID" ), _
Array("IL", "IL" ), _
Array("IN", "IN" ), _
Array("IA", "IA" ), _
Array("KS", "KS" ), _
Array("KY", "KY" ), _
Array("LA", "LA" ), _
Array("ME", "ME" ), _
Array("MA", "MA" ), _
Array("MD", "MD" ), _
Array("MI", "MI" ), _
Array("MN", "MN" ), _
Array("MS", "MS" ), _
Array("MO", "MO" ), _
Array("MT", "MT" ), _
Array("NE", "NE" ), _
Array("NV", "NV" ), _
Array("NH", "NH" ), _
Array("NJ", "NJ" ), _
Array("NM", "NM" ), _
Array("NY", "NY" ), _
Array("NC", "NC" ), _
Array("ND", "ND" ), _
Array("OH", "OH" ), _
Array("OK", "OK" ), _
Array("OR", "OR" ), _
Array("PA", "PA" ), _
Array("RI", "RI" ), _
Array("SC", "SC" ), _
Array("SD", "SD" ), _
Array("TN", "TN" ), _
Array("TX", "TX" ), _
Array("UT", "UT" ), _
Array("VT", "VT" ), _
Array("VA", "VA" ), _
Array("WA", "WA" ), _
Array("WY", "WY" ), _
Array("WI", "WI" ), _
Array("WV", "WV" ) _
)
Application.Lock
Application(KEY) = sStates
Application.UnLock
Else
sStates = Application(KEY)
End If</FONT>
<FONT face="Courier New" size=1> sSelectedState = Session("State")
For i = 0 To 50 'The number of states is not likely to change
If sSelectedState = sStates(i)(0) Then
sSelected = " SELECTED"
Else
sSelected = ""
End If
Response.Write( _
"<option value='" & sStates(i)(0) & "'" & sSelected & ">" & _
sStates(i)(1) & _
"</option>" _
)
Next
End Function
</script></FONT>
<FONT face="Courier New" size=1><select class="f" name="State">
<%=RenderStates%>
</select>
</FONT>
<FONT face="Courier New" size=1></FONT>
Admin
Washington D.C. isn't a state, and if you are going to include it in a state list for whatever reason you are going to have 51, not 50.
Admin
Most lists of states include Guam, Puerto Rico, etc. I've worked with lists of states that included Germany.
Admin
A time _complexity_ of O(log n) means the task is accomplished in
(a+b*log n) steps for some constants a and b. Depending on the size of b, the above numbers are possible. Generally, O(x) does not say how long something takes, but how fast the time needed grows with the size of the problem. So, for small problems, an algorithm of O(2^n) can be faster than another algorithm of O(n).
Admin
I have a degree in Computer Science, but thanks. I asked how you get that for 50 states where the state codes are 2 letters each.
Admin
ah, i see you speek Perl also :)
Admin
The killer is having 50 boolean variables, with only one of them being true.
The fastest way to do this would require the developer to abandon the 50 individual boolean variables, perhaps replacing with a boolean array (IF YOU INSIST). VB code migration can be eased by changing the 50 boolean variables into 50 integer constants to index the boolean array.
A blazing fast lookup method would create a string variable with delimited state abbreviations and use the InStr() function to search all the two-character state abbreviations in one statement. Special cases, such as "D.C." would require other checks.
Example:
<FONT face="Courier New"><FONT color=#0000ff>Dim</FONT> bStateSel(0 to 49) As Boolean
<FONT color=#0000ff>const</FONT> selCA As Integer = 0
<FONT color=#0000ff>const</FONT> selNY As Integer = 1
<FONT color=#0000ff>const</FONT> selIL As Integer = 2
<FONT color=#0000ff>const</FONT> selFL As Integer = 3
<FONT color=#0000ff>const</FONT> selNV As Integer = 4
strStateAbbr = "CA;NY;IL;FL;NV;"
intStateIndex = <FONT color=#0000ff>InStr</FONT>(strStateAbbr, session("State") & ";")
<FONT color=#0000ff>If</FONT> intStateIndex = 0 <FONT color=#0000ff>Then</FONT>
'look for strange states such as "D.C."
<FONT color=#0000ff>Else</FONT>
'convert to bStateSel position value and update array
intStateIndex = (intStateIndex -1) \ 3
bStateSel(intStateIndex) = True
<FONT color=#0000ff>End If</FONT></FONT>
======================
Maybe it would be best to use the SelectedIndex property to immediately produce an index to the bStateSel array.
Example:
<FONT face="Courier New">intStateIndex = Document.OrderForm.State.SelectedIndex
</FONT>bStateSel(intStateIndex) = True
Admin
wtf is this? an eyechart?
Admin
No, you asked
In the formula (a+b*log n), choose 20000 for b and 1759 for a. Not a likely value for this kind of task (like I said before), just a justification about joe_bruin's wrong interpretation of O(log n)
Admin
"justification" is the wrong word, i meant "adjustment"
Admin
I'm no VB expert but, I have never known substring searching to be blazing fast in any language.
Admin
I don't know what kind of iterpretation you are using for big notation, but the whole point is to ignore a + b. When we are talking about the number or operations a specific task takes in the context of big O, it's generally assumed we are talking about the same high-level operations that contribute to the big O.
Admin
Depending on how it is implemented you might eventually have up to 147 string comparisons.
Admin
The point is that the O notation does not give you the exact number of operations, only an indication about the growth of that number in relation to the growth of the input data.
So, if some function has the complexity O(ln n), it's wrong to say that you need 4 operations for 50 input values.
Admin
Admin
Is the code of question of the day generated by a WYSWYG designers like Dreamweaver?
The code reminds of that...
Admin
In principle you should be able to work with DHTML object server-side and then simply call some render method to generate the html. Might look something like this.
<%
Dim objSelect, _
objOption, _
objNode
Set objSelect = Server.CreateObject("DHTML.Select")
objSelect.Class = "f"
objSelect.Name = "state"
Foreach objNode in objValueCollection 'or whereever the entries comes from
Set objOption = Server.CreateObject("DHTML.Option")
objOption.Value = objNode.Key
objOption.InnerHTML = objNode.Value
If Session("state") = objSelect.Value Then
objSelect.Selected = true
EndIf
call objSelect.Options.Add( objOption )
Next
Response.Write objSelect.toHTML
%>
Admin
Is the code of question of the day generated by a WYSWYG designers like Dreamweaver?
When I knew zip about ASP (three years ago), I had Dreamweaver write the code for me. Click, click, Repeat Region, MasterDetail click click etc.
I thought I was being pretty cool.
Trust me when I say this WTF's code is advanced and highly optimised compared to the shovelfuls of dirt Dreamweaver put on my screen.
Though it's possible that Dreamweaver has improved bits and now actually does generate code with a semblance of cleanliness.
Admin
Our (the company's I work for) e-commerce sites include the state of Canada, and the little known states of Aypeow and Feepoe (APO, FPO, respectively, annexed surreptitiously during the NYC blackout of the 1970s).
It also includes the Federated States of Micronesia (5 of them annexed sometime after the fall of Constantinople, the other 12 later joined in out of exhaustion) and the state of Palau (incorporated into the Union during the French Revolution).
I think all of you need to update your lists (and maybe buy a new flag) since there is definitely more than 50 states.
dZ.
Admin
That's no Perl...
That's a Space Station!
dZ.
<font size="2">P.S. I have a very bad feeling about this...</font>
Admin
You make a good case against hungarian notation.
Admin
Ah, he just wrote a simple code generation utility, and that's his testcase :)
Admin
I'm not exactly sure why but I think I'd feel dirty after providing a server-side DHTML solution.
Admin
At the abstraction level that we mostly work in, it's pretty difficult to know exactly how many machine operations are required for any piece of code.
In get your point now but hyperbole is rarely a good way to make a point.
Admin
errr all you have to do is
<font size="2"> selectBox.SelectedIndex = selectBox.Items.IndexOf( selectBox.Items.FindByValue( session("State").ToString() ) );</font>
or am i missing something?
Admin
I'd feel dirty after using the word 'DHTML'.
Admin
True enough, but the size of this array is still unlikely to change. (whether it's 5, 50, or 51)
Admin
Also, 50 in a zero-based array is element number 51.
Admin
At least in the US, the USPS gives out a nice file that has all of the long/lat of each zipcode - including the city, state, and county. As an added bonus you get the type of post office supports that zipcode. Its not that big - my table for the US is just over 42k rows. After shoving that, ISO country codes, NPANXX codes, and state codes into the database I can provide the user with at least a fairly good guess of location.
Still IP phones and number porting means that I have to accept limitations on the interface's ability to help the user along with filling out the form.
Admin
This must be why I often have to argue with service representatives about where I live.
Admin
I think the original code is "classic" ASP, not .Net.
Admin
I vbscript i allways prepend my variable names with either int, lng, str, bool, or obj. I don't do it in any other languages but it's really practical in vbscript functions or subs because you can easily see the type of the parameter that need to be passed;
Function Foo( strMessage, intCount )
Dim intIterator
Foo = ""
For intIterator = 0 To intCount
Foo = Foo & strMessage & vbCrLf
Nextv
End Function
Sub Bar( strMessage, intCount, strOut ByRef )
strSub = ""
For intIterator = 0 To intCount
strSub = strSub & strMessage & vbCrLf
Nextv
End Sub
With regard to the whole discussion about whether or not it's a good idear to use hungarian notation, can't we just agree that whatever notation you choose to do - use it consistantly.
Mind you i only this notation for variable within a script. request paramters are just lower case with no indication of type.
Admin
hmm...
Admin
Errr.
Shouldn't that be:
Sub Bar( vntMessage, vntCount, vntrefOut ByRef )
[:)]
After all, in VBScript there is no type but variant.
Admin
I suppose even I can see the value in this for parameter names in VB, since it's weakly typed. It sets an expectation that otherwise would not exist.
Admin
correct: my hungarian worts denote the variant sub-type:
Since i'm anal-rententive it's something i like to keep track off throughout my program.
Admin
This is bad, but not quite to the level of a PowerBuilder app I saw. Instead of implemeting a dropdown that contained all the states from a table, it made use of a datawindow and a radio button. That's right, an entire window was devoted to selecting a state, unbelievable to me at the time. But, now I see far worse things exist to maintain...
Admin
Assuming I understand you correctly....
I had the displeasure of working with HTML DB (ships with Oracle 10g) which uses a new window for every multi-select, and just displays the items as a list of links. Dreadful....positively dreadful.
Admin
There are also a few "state" codes used by the US military to send mail to military bases in various regions of the world.
Admin
And it's not uncommon for Candanian provinces and Mexican states to be added to a list of US states at some point in the apps lifecycle.
It's annoying when you want to enter a Canadian postal code but the software only allows numbers.
Admin
I've always wanted to go to .... I heard it's beautiful this time of year. I believe it's "The Eveything Else State". Love it.
Admin
Maintain it?!?!? Burn it to the ground and start over. It would be faster.
Admin
The Canadian province codes do not overlap the U.S. state codes. Good design.
Or the other way around. I was transferred to the U.S. I tried to enter a change of address for one of my credit cards. Said company's site does not accept addresses outside of Canada.
I called about this. It is deliberate policy. A policy WTF.
I was told that I should get a Canadian address. I turned into a second-class citizen, because I am about one-half hour south of the border! It was easier to quit dealing with them.
Sincerely,
Gene Wirchenko
Admin
Looks like our wanna-be-programmer accidently removed all the </ </ body empty...< something by>
Admin
In this case, InStr() will be a much faster search than either <FONT face="Courier New">Select Case</FONT> or <FONT face="Courier New">If...ElseIF</FONT> constructs. In general, recoding the search options often provides superb performance improvements over other string comparison methods.
Note: doing case-insensitive searches with VB's InStr() function is not very efficient (maybe 8x slower than case-sensitive searches) and may be an instance where other methods or additional steps need to be taken.
Another speedy option is to use hashing of the search arguments to allow numeric searching.