|
Well, the example wasn't too detailed but as-is it took OOP and bastardized it into a function library (PersonFacade) + simple data structures (Person).
You do want your persistance layer (data) to be separate but working at the business layer (often from a different class) and calling data layer specific persistance methods is ugly not to mention a pain in the ass to manage.
A much cleaner solution is to have a Save() method (and depending on your scheme, a Delete()method) which then passes itself to a data layer so in your business & UI logic you don't need to call data layer specific methods residing in a completely different class. The business object takes care of itself and your code is better organized. The data layer could look like the "facade" thing or could be a smarter all-encompasing gate keeper.
|
|
|
|
|
Great point. Never thought of it that way. But it wasn't a sennior programmer making things clearer, nor a junnior one making misstakes. It's just some guy who has been programming for a while and I guess has no clue how boolean expressions work. It's started on C# by the way. Original code
x => if (SomeBoolMeth(x) == true) return true; return false ;
If you were a professor and find this in some test, not from a basic course, what would you do??
Again: Great point!!
|
|
|
|
|
Either you've understood that "(x < 5)" is a boolean expression every bit as much as the boolean constants "true" and "false", or you haven't. There's nothing in between. The code makes it look as if the condition is somehow not a boolean expression, and therefore highlights the author's lack of understanding, of something quite fundamental, and therefore deserves to be on display as a coding horror, in my opinion.
For some reason I see this done a lot with ternaries in C#:
return (s == "toto"? true : false);
Unfortunately proper use is less commonly seen, such as
return (row != null? (int)row["count"] : -1);
|
|
|
|
|
What is x declared as? It's not a var is it?
|
|
|
|
|
Good catch!
Here could be trying (although not recommended) for "object == true".
|
|
|
|
|
what if x was a nullable boolean ?
<br />
static bool getX(Nullable<bool> x)<br />
{<br />
if(x==true)<br />
{<br />
return true;<br />
}<br />
else <br />
{<br />
return false;<br />
}<br />
}<br />
</bool>
|
|
|
|
|
that didn't quite come out right ( first post :P ) was supposed to be a bool after the Nullable of course
static bool getX(Nullable<bool> x)</bool>
|
|
|
|
|
uggh, ok last attempt I am sure you follow ..
Member 4364689 wrote: static bool getX(Nullable<bool> x)
|
|
|
|
|
It still makes no difference. An if condition is a boolean expression and can only evaluate to true or false, regardless of whether the equals operator is working with operands that are structures (such as Nullable<bool>) or objects (such as the object == true mentioned above) or anything else.
It is of course true that the expression "x" cannot in general be known to be equivalent to "x == true", but you can ALWAYS rewrite
if (x == true)
return true;
else
return false;
to just
return (x == true);
And of course, if x is in fact a bool, it would be clearer to simply return x.
|
|
|
|
|
So much for just doing a return x==true;
If x is a bool, then just a simple return of x will work
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
I considered creating a new thread for this, but (obviously) decided not to.
I spent yesterday at the "Heroes happen {here}" event (in Phoenix) and most of the demoes in the "developers' track" was presented by a "developer evangelist", and it seemed like every one of his methods that returned a bool was written in that form.
|
|
|
|
|
I wrote my first game when I was about 14 or 15, on my lovely Amiga 1200. I did not really know what I was doing, but the outcome was quite good (it was a MadTV clone, but with a radio station). I still have my old Amiga, and just for the fun of it, I took a look at my old code (which was written in CanDo... guess nobody knows it). I was pretty amazed of what I did without knowing what I did, but I stumbled upon a... "concept" that I used pretty often. It basically looked like this (pseudo code):
if not rect.PointInRect(point) or control.IsDisabled() then<br />
DoNothing()<br />
else<br />
... # Some real code here<br />
endif<br />
DoNothing is not a dummy here, it was an actual function. Yes, I had a function that just did... nothing And I used it pretty often. Oh, and the "else" part was not always there. Sometimes I only had the if/DoNothing part (no idea what sense that made to me when I was a kid).
So what tells me this? I was able to get a full game up and running, but knew sh*t about boolean algebra and how these strange if-thingies work. It still makes me giggle.
|
|
|
|
|
|
1 for stupidity?
WPF - Imagineers Wanted
Follow your nose using DoubleAnimationUsingPath
|
|
|
|
|
I didn't do anything that spectacular, but when I was 16 I wrote a tetris clone in turbo pascal for the final project of my 2nd year programming class. Then over the summer I started writing a top scrolling shooter game, I got the engine to what I estimated was 60-80% complete before the accumulated WTFs I was developing made me take what ended up being a permanent break. The biggest of them was that my code was object oriented, but I was fully self taught and had no idea of the concept of polymorphism. Instead my MovingObject class used function pointers to handle different forms of behavior. This kinda sorta worked but was a real pita in implementation and kept failing for reasons I could never figure out.
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop.
-- Matthew Faithfull
|
|
|
|
|
The worst coding I ever did as a kid was to write programs that used dozens of variables because I hadn't learned about arrays yet.
|
|
|
|
|
Oh I knew about arrays! There was one huge array with all the game variables (for save games)... oh yes it was HUGE...
|
|
|
|
|
ClementsDan wrote: I hadn't learned about arrays yet
I on the other hand...
In my first programming course (using BASIC-Plus on a PDP-11) one of the assignments was to do something (I forget what) with a bunch of numbers and it was expected that we would use a bunch of individual variables. But I said to myself, "there's gotta be a better way", and proceeded to read the next chapter of the book, which covered "subscripted variables" (arrays). So I wrote my program using them and turned it in. The teacher replied, "that's next week's assignment!"
|
|
|
|
|
I remember CanDo!!!
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Cool
|
|
|
|
|
Tak wrote: if not rect.PointInRect(point) or control.IsDisabled() then
DoNothing()
else
... # Some real code here
endif
I think you knew more about programming than you realized. You were obviously thinking about future extensions and nice features you could add within the DoNothing function. I bet if you had to continue to work on the game today you would be happy the handy DoNothing you put there many years ago. And people would be wondering, how could someone be so brilliant when he was only 14 or 15?
|
|
|
|
|
One of my proteges[^] is working for a company who swears that the "best" way to do TDD is to write the code first, and then make the test pass AFTER everything has been written. He has pretty much done everything he possibly could to convince the management and his coworkers that they've got it all backwards, but they insist that they don't need to learn anything about patterns since their Oracle Framework (which is a Developer Preview edition, btw) 'does all the work of patterns for us'.
Here's a sample snippet of their work. It's in Java, so beware of the hanging curly braces:
public void doFind(){
log.debug("Search records");
DCBindingContainer bc = (DCBindingContainer)getBindings();
DCIteratorBinding ib = getBindedIterator(bc,TABLE_ITERATOR);
AdfFacesContext context = AdfFacesContext.getCurrentInstance();
String pScope = context.getProcessScope().get("strAction").toString();
log.debug("Process scope = " + pScope);
if(pScope.equalsIgnoreCase("advanceSearch")){
log.debug("Do advance search");
ViewCriteria vc = ib.getViewCriteria();
Row row = vc.first();
row.refresh(Row.STATUS_INITIALIZED);
if(codeFrom.getValue() != null &&
!codeFrom.getValue().equals("")) {
if(codeTo.getValue() != null &&
!codeTo.getValue().equals("")) {
row.setAttribute("ApInvcTypeCode",
" between '" + codeFrom.getValue() +
"' and '" +
codeTo.getValue() +
"'");
}else {
row.setAttribute("ApInvcTypeCode",
" like '" + codeFrom.getValue() +
"%'");
}
}else{
codeFrom.setValue(null);
}
if(latinName.getValue()!=null && !latinName.getValue().equals("")){
row.setAttribute("ApInvcTypeLatinName",
" like '" + latinName.getValue() + "%'");
}else{
latinName.setValue(null);
}
if(arabicName.getValue()!=null && !arabicName.getValue().equals("")){
row.setAttribute("ApInvcTypeArabicName",
" like '" + arabicName.getValue() + "%'");
}else{
arabicName.setValue(null);
}
if(effStartDateFrom.getValue() != null &&
!effStartDateFrom.getValue().equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if(effStartDateTo.getValue() != null &&
!effStartDateTo.getValue().equals("")) {
row.setAttribute("EffStartDate",
" between '" + sdf.format(effStartDateFrom.getValue()) +
"' and '" +
sdf.format(effStartDateTo.getValue()) +
"'");
}else {
row.setAttribute("EffStartDate",
" = '" + sdf.format(effStartDateFrom.getValue()) +
"'");
}
}else{
effStartDateFrom.setValue(null);
}
if(effEndDateFrom.getValue() != null &&
!effEndDateFrom.getValue().equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if(effEndDateTo.getValue() != null &&
!effEndDateTo.getValue().equals("")) {
row.setAttribute("EffEndDate",
" between '" + sdf.format(effEndDateFrom.getValue()) +
"' and '" +
sdf.format(effEndDateTo.getValue()) +
"'");
}else {
row.setAttribute("EffEndDate",
" = '" + sdf.format(effEndDateFrom.getValue()) +
"'");
}
}else{
effEndDateFrom.setValue(null);
}
}else{
log.debug("Do basic search");
}
OperationBinding ob = bindings.getOperationBinding("Execute");
ob.execute();
ib.setFindMode(false);
getChangesFlag().setValue(0);
AdfFacesContext.getCurrentInstance().getProcessScope().put("strAction","");
}
To add insult to injury, their "Senior Level" developers supposedly have two to three years of experience, and yet, they have problems understanding recursion; to them, it's practically a black art. They don't understand what refactoring is, nor do they spend any time reading any programming journals or articles online unless there's a problem in their code that they can't fix. The sad thing is that my former apprentice has to put up with these people, and they dismiss his "crazy" advice from books such as the Mythical Man Month as pure hogwash. They insist that since they have their application "framework", they don't need to worry about reading any useless books--it does everything for them.
I can't publicly say the name of the company, but if you happen to do any outsourcing in the Philippines and want to know the name of this company so you can avoid it, send me a private message, and I'll tell you exactly who it is.
The moral of the story: If you're going to outsource to any company, make sure you get some thorough code samples of their work before paying them a cent. Otherwise, you just might end up with a company like this.
|
|
|
|
|
Philip Laureano wrote: The moral of the story: If you're going to outsource to any company, make sure you get some thorough code samples of their work before paying them a cent. Otherwise, you just might end up with a company like this.
*sob*
I mentioned something earlier today about perhaps interviewing the new consultants before setting 'em loose on our apps. No such luck.
But who is the king of all of these folks?
|
|
|
|
|
Tell him that if it was supposed to be that way they would have called it Development Driven Test (DDT) instead
|
|
|
|
|
I'm a great fan of shorties. I'll have to miss most of the source for the usual reasons, but the last two lines made me do a double-take...
(within class FeedMetaData, C#)
virtual FeedMetaData Send(FeedValidationErrorHandler handler)
{
this.Dispose();
return this;
}
|
|
|
|