|
An ex-coworker asked me to help him with his first website (maybe last?).
It's for a real estate agency. He was stuck trying to process the search form with some selects (price range, state size, zone location, bla, bla.. )
All the code is a f***ing mess, but this piece of crap excels among all other:
$filter='';
$type=$_POST['type'];
$admin=$_POST['admin'];
$zone=$_POST['zone'];
$m2=$_POST['m2'];
$price=$_POST['price'];
if(($type!="selec") AND ($admin!="selec") AND ($zone!="selec") AND ($m2!="selec") AND ($price!="selec")){
$filter="type=\"$type\" AND admin=\"$admin\" AND price>=\"$pricemin\" AND price<=\"$pricemax\" AND city=\"$city\"";
}elseif(($type!="selec") AND ($admin!="selec") AND ($pricemin!="") AND ($pricemax!="")){
$filter="type=\"$type\" AND admin=\"$admin\" AND price>=\"$pricemin\" AND price<=\"$pricemax\"";
}elseif(($type!="selec") AND ($admin!="selec") AND ($pricemin!="") AND ($city!="")){
$filter="type=\"$type\" AND admin=\"$admin\" AND price>=\"$pricemin\" AND city=\"$city\"";
}elseif(($type!="selec") AND ($admin!="selec") AND ($pricemax!="") AND ($city!="")){
$filter="type=\"$type\" AND admin=\"$admin\" AND price>=\"$pricemax\" AND city=\"$city\"";
}elseif(($type!="selec") AND ($pricemin!="") AND ($pricemax!="") AND ($city!="")){
$filter="type=\"$type\" AND admin=\"$pricemin\" AND price>=\"$pricemax\" AND city=\"$city\"";
}elseif(($type!="selec") AND ($pricemax!="") AND ($city!="")){
$filter="type=\"$type\" AND price>=\"$pricemax\" AND city=\"$city\"";
}elseif(($type!="selec") AND ($pricemax!="") AND ($city!="")){
$filter="type=\"$type\" AND price>=\"$pricemax\" AND city=\"$city\"";
}elseif(($type!="selec") AND ($admin!="selec")){
$filter="type=\"$type\" AND admin>=\"$admin\"";
}elseif(($type!="selec") AND ($pricemin!="")){
$filter="type=\"$type\" AND price>=\"$pricemin\"";
}elseif(($type!="selec") AND ($pricemax!="")){
$filter="type=\"$type\" AND price>=\"$pricemax\"";
}elseif(($type!="selec") AND ($city!="")){
$filter="type=\"$type\" AND city>=\"$city\"";
}elseif($type!="selec"){
$filter="type=\"$type\"";
}elseif($admin!="selec"){
$filter="admin=\"$admin\"";
}elseif($pricemin!=""){
$filter="price=\"$pricemin\"";
}elseif($pricemax!=""){
$filter="price=\"$pricemax\"";
}elseif($city!=""){
$filter="city=\"$city\"";
}
$filter="";
}
I always knew he is not a genius.. but never thought someone could write code like this without realizing he was wrong
¿Eres tu John Wayne? ¿O soy yo? (Sorry about my english!)
|
|
|
|
|
Looks like perfectly normal PHP to me. You mean PHP doesn't have to look like a child wrote in in Quick Basic? If true, I am amazed...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
The ability to write total garbage is language- (and culture-) independent.
with the possible exception of APL, where nobody can tell if it's garbage or clever code. Described to me years ago as the world's first write-only language.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Thanks! I've been trying to forget the existence of APL...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
No exception, it's possible to write good and bad APL, or even J. The problem is that it has more features, so it's easier to abuse, and a lot of it is written by academics who don't really believe in professional software practices.
|
|
|
|
|
that actually DOES look like something i wrote in qbasic when i was 10.
|
|
|
|
|
ahhh crap, I think I just had a stroke
I may or may not be responsible for my own actions
|
|
|
|
|
"One can write Fortran in any language."
Time you enjoy wasting is not wasted time - Bertrand Russel
|
|
|
|
|
Well a comment or two would be pretty handy, as well as some better spacing (though I'm hoping you crammed it all together so it would fit better on the page?). That is one heck of a if statement though...
|
|
|
|
|
No, i didn't.. Sad but true
I've translated names and wrote the few comments...
¿Eres tu John Wayne? ¿O soy yo?
modified on Wednesday, June 8, 2011 12:59 PM
|
|
|
|
|
And I thought I was bad with comments... wow!
|
|
|
|
|
comments is the least of this codes problems.
|
|
|
|
|
D'oh! My Usual comments are not like this -_-'... Those were fast ones just for this post
¿Eres tu John Wayne? ¿O soy yo?
|
|
|
|
|
Wow this is very nice code.
I´ll zeropad it to fixed line length copy an inversion of it to the front, rotate counterclockwise 90 degrees, apply a color index substitution. Et voila, we´ve got a sprite for a space invaders clone.
|
|
|
|
|
I just went in to fix a compatibility issue in some code and ran into this beautiful 27 lines long list of variables set to an empty string. Then the code has a loop going through the provided data, which has a list of if statements in it, of which you can probably guess the length. All but 5 or so of these ifs have duplicate code. After the loop all these variables are passed to a constructor, which holds another nice long list of if statements...
Code: http://pastebin.com/uz3uMy0g[^]
It's GPL v2, so do feel free to use it!
|
|
|
|
|
... art... it's art...
<br />
public function SMWBibTeXEntry( <br />
$type, <br />
$address, <br />
$annote, <br />
$author, <br />
$booktitle, <br />
$chapter, <br />
$crossref, <br />
$doi, <br />
$edition, <br />
$editor, <br />
$eprint, <br />
$howpublished, <br />
$institution, <br />
$journal, <br />
$key, <br />
$month, <br />
$note, <br />
$number, <br />
$organization, <br />
$pages, <br />
$publisher, <br />
$school, <br />
$series, <br />
$title, <br />
$url, <br />
$volume, <br />
$year ) {<br />
<br />
if ( $type ) <br />
$this->bibTeXtype = ucfirst( $type ); <br />
else <br />
$this->bibTeXtype = 'Book';<br />
<br />
$fields = array();<br />
<br />
if ( $address ) $fields['address'] = $address;<br />
if ( $annote ) $fields['annote'] = $annote;<br />
if ( $author ) $fields['author'] = $author;<br />
if ( $booktitle ) $fields['booktitle'] = $booktitle;<br />
if ( $chapter ) $fields['chapter'] = $chapter;<br />
if ( $crossref ) $fields['crossref'] = $crossref;<br />
if ( $doi ) $fields['doi'] = $doi;<br />
if ( $edition ) $fields['edition'] = $edition;<br />
if ( $editor ) $fields['editor'] = $editor;<br />
if ( $eprint ) $fields['eprint'] = $eprint;<br />
if ( $howpublished ) $fields['howpublished'] = $howpublished;<br />
if ( $institution ) $fields['institution'] = $institution;<br />
if ( $journal ) $fields['journal'] = $journal;<br />
if ( $key ) $fields['key'] = $key;<br />
if ( $month ) $fields['month'] = $month;<br />
if ( $note ) $fields['note'] = $note;<br />
if ( $number ) $fields['number'] = $number;<br />
if ( $organization ) $fields['organization'] = $organization;<br />
if ( $pages ) $fields['pages'] = $pages;<br />
if ( $publisher ) $fields['publisher'] = $publisher;<br />
if ( $school ) $fields['school'] = $school;<br />
if ( $series ) $fields['series'] = $series;<br />
if ( $title ) $fields['title'] = $title;<br />
if ( $url ) $fields['url'] = $url;<br />
if ( $volume ) $fields['volume'] = $volume;<br />
if ( $year ) $fields['year'] = $year;<br />
<br />
[...]<br />
<br />
jep... it is...
(yes|no|maybe)*
|
|
|
|
|
Ohh that makes my brain hurt. He uses arrays but cant pass an array. Either the language limits passing arrays or he is a moron. Let me just assume the answer to that and we will move on
Brad Barnhill
|
|
|
|
|
See this piece of code:
class Person
{
private string name;
private string sname;
public Person(string argName, string argSName)
{
name = argName;
sname = argSName;
}
public string getName()
{
return name;
}
public string getSName()
{
return sname;
}
public override string ToString()
{
return name + " " + sname;
}
}
Now consider these few facts:
- the code is in C#, not Java
- in case you haven't noticed, this code violates some basic good-style C# coding guidelines
- the person who wrote this code teaches C# programming at university
- this piece of code was given to his students as a do-it-like-this example
- he never, ever uses properties (Java-style getXXX() and setXXX() methods seem to be good enough for him...)
- he sometimes names his classes and methods in Czech using diactitics (yes, it compiles fine since VS is Unicode-based, but... WTF?)
- And more!
|
|
|
|
|
Kubajzz wrote: - in case you haven't noticed, this code violates some basic good-style C# coding guidelines
I haven't noticed. Can you provide an explanation with an example? Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Sure
First of all, properties should be used in C# instead of get() and set() methods wherever appropriate.
Public member names should start with a capital letter.
Prefixes such as "arg..." are evil. The constructor parameters should be simply "name" and "sname".
The name "SName" is a great example of an unclear and unneccessary abbreviation that should be avoided.
I was too lazy to search for reference links, this is what I remember from the guidelines. Somebody correct me if I'm wrong...
|
|
|
|
|
Thanks. I understand your points. In this day and age, using "SName" instead of say "Surname", whilst seemingly picky is a good point. Sometimes it's all about the attention to details.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Oh dear god no!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
It happens. At University we had teachers that tought us, and teachers that we tought
I may or may not be responsible for my own actions
|
|
|
|
|
Congratulations. You have found the main source of the content in hall of shame: shameful teachers.
|
|
|
|
|
I like the way they explicitly declare methods as public when the class is implicitly internal.
BTW I am a teacher so if you want to pass, hand in your assignments
"You get that on the big jobs."
|
|
|
|