|
Disclaimer: I forsee a lot of disagreement in terms of legacy code. This is only pertinent to Green or Refactoring Projects.
Assuming we're working with S.O.L.I.D. Object-Oriented Design, when would NON Short-Circuited Eval be acceptable? I assert that it is not acceptable, but need dicsussion points of agreement or disagreement.
There are obvious times that Lacking Short-Circuit Eval is Bad and should be fixed no matter what:
If FirstName.Length > 5 And FirstName(5) = "f"c Then
End If
if (FirstName.Length > 5 & FirstName(5) == 'f') {
}
The above conditional evaluation should instead be AndAlso to short-circuit the checking of the sixth (index: 5) character. But what about this example?
If CaseClass.ParseCase(Data) And ClientClass.ParseClient(Data) And CourtClass.ParseCourt(Data) Then
End If
If (CaseClass.ParseCase(Data) & ClientClass.ParseClient(Data) & CourtClass.ParseCourt(Data)){
}
The above code isn't automatically clear to anybody that: if all three methods don't run, code later on down the line will not be able to do its job.
However, we have some code which we only want to evaluate on the condition that the result of those Parse methods all return TRUE. So the author of this code removed the Short-Circuiting.
In the above code, it's logical to remove the short-circuiting so all three methods evaluate, but the lack of clear objectives makes maintainence a nightmare. In fact, it then requires Comments to say "MUST EVALUATE ALL THREE, Don't Short-Circuit!", and requiring Comments means code is getting smelly.
So, if there is a Requirement to ALWAYS Short-Circuit, we are forced to do this:
Call CaseClass.ParseCase(Data)
Call ClientClass.ParseClient(Data)
Call CourtClass.ParseCourt(Data)
If CaseClass.Success AndAlso ClientClass.Success AndAlso CourtClass.Success Then
End If
CaseClass.ParseCase(System.Data);
ClientClass.ParseClient(System.Data);
CourtClass.ParseCourt(System.Data);
if (CaseClass.Success && ClientClass.Success && CourtClass.Success) {
}
Above, our objective is very clear that we want to run all three, and that we want to perform conditional work based on the success of the three runs. Thus, requiring Short-Circuiting also forced us to write code with clear objective.
Also, this requires us to write classes with single responsibility and clear objectives also, as well as follow other SOLID Practices.
I can't personally think of a time when NON Short-Circuiting conditionals were the right choice. As a matter of fact, most of the time I've seen NON Short-Circuiting evaluation, it ended up breaking or was obvious to break soon.
Last Note... one of my biggest Pet Peeves in VB is the use of the Non-Ternary IIF Function. Partially because it breaks this proposed rule of requiring Short-Circuiting, but mostly because I've never seen an IIF() That requires the use of its NON short-circuiting Behavior.
Dim intTest As Integer = 0
Dim blnLMAO As Boolean = IIF(2=2, Integer.TryParse("3", intTest), Integer.TryParse("4", intTest))
What's the value of intTest? Well, since 2=2, we'd assume it's 3. Lawl, wrong. Just delete one of the I's and use the IF() Ternary Expression (not a function), it actually does what you expect it to. Also, IIF() Isn't Type-Safe, it returns Object, and is even less explicit in its objective. C# doesn't even have an equivilent.
In support of my reference, I site a 200+k super user on StackOverflow who had this answer. I didn't take part in this question, but found it while researching. However, while it advocates Short-Circuiting, it does not provide me with the discussion necessary to say that we REQUIRE Short-Circuiting in all future code: Short-Circuiting Advocation
So, anybody have any discussion points on why Requiring Short-Circuit Evaluation would/wouldn't be a bad Requirement?
There are only 10 kinds of people in the world: Those who don't get this, and those who have heard it too many times.
~Suamere
|
|
|
|
|
How to find out installed browser list in a asp.net by using C#?
Reply If anyone knows...!
Thanks In Advance ...
|
|
|
|
|
You can't retrieve a list of installed applications on the client using a server-side language.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Then What to Do.. Thanks For Reply...
|
|
|
|
|
Change your requirement. Why do you need to find out what browsers the client has installed?
|
|
|
|
|
I am creating Safe guard web application.If User is Under The Age of 18 then He/She Cant able to access the illegal websites for e.g (www.youtube.com)I have to block Some websites that's why I need to List Of all Installed Browsers ...Somebody Have some Code To find out Installed Browsers in .NET Framework..Then Reply ..
Thanking You All For Replying.........
|
|
|
|
|
That's not the way to do it - your question implied that you were running this from the web, but you are actually talking about a client side application here. What you need to do is to act like a filter instead - don't worry about the browser part.
Basically, your code needs to intercept outbound requests and check to see the destination.
|
|
|
|
|
That's the wrong way to approach this. You can't possibly individually support the dozens of different browsers out there.
What you should be writing is a proxy server. This is standard, off-the-shelf functionality for any proxy server so you'd be re-inventing was has already been written dozens of times.
|
|
|
|
|
Using Javascript can easily help you get the browser you are currently accessing.
You may be able to get a list of installed browsers using ActiveX. This will not make your site very secure and users may refrain from using it.
|
|
|
|
|
Abhinav S wrote: You may be able to get a list of installed browsers using ActiveX. That'd exclude Lynx, and my portable SeaMonkey browser. So, while one would get a list, it's not guaranteed that any of those are actually used.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks For Reply ..Will You Please Tell me How to Use ActiveX Control ?
............
|
|
|
|
|
Member 8134979 wrote: Will You Please Tell me How to Use ActiveX Control ? I suggest you research it yourself first. I'll gladly help if you get stuck or have specific questions.
You should learn how a browser and a server works, before trying to secure them. What you'd want is called a firewall. ActiveX isn't going to help, and identifying browser is also not going to help. I don't need a browser to download some pr0n.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
ok... Thanking You To All.................
|
|
|
|
|
You can't retrieve a list of the installed browser using a server-side language.
Even if you could it would be practically useless since some browsers would not appear in that list (as SeaMonkey, for example).
What you can try is to get the browser which is used to access your website, but even that stands on shacky feet since not every browser transmits its name correctly.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
while running ,on binding navigator "delete" , add and all buttons aren't displaying their own color
means delete ---red
|
|
|
|
|
More info is required. Are you facing this problem in WCF or WinForms?
|
|
|
|
|
hi all am facing problem with binding Navigator AddNew Item in C#.
here is my code:in AddNewItem_Click
inventoryBindingSource.Insert(inventoryBindingSource.Position +1, inventoryBindingSource.List);
what can i do;
it's giving error as
Cannot insert external objects to this list.
|
|
|
|
|
how to convert any web page into pdf by passing the url of the page on button click event
|
|
|
|
|
Use the ASP.NET forum.
Veni, vidi, abiit domum
|
|
|
|
|
|
|
We have set of business entitles which are serialized using XML serialization and that XML is encrypted using TripleDESCryptoServiceProvider() .NET API and stored in SQL server database.
Everything was working fine.
On 10/10/2013 suddenly we observed that our application started throwing attached error and stopped working.
After lot of investigation we found that our application is unable to decrypt previously encrypted XML data stored in Database.
Above problem is reproduced at various user production sites and they are unable to use our application.
This problem is critical as our users are unable to use our application.
After lot of RND we found that one of the critical windows auto update installed on 09/10/2013 or 10/10/2013 (attached as a sample) is causing the problem.
i.e. After roll backing these updates or reinstalling .NET 4.0 framework does resolve this critical problem.
Currently we are handing above issue at our customer's live environment on case to case basis.
We need to find out proper solution for above problem as soon as possible. Please help us to resolve above critical issue as soon as possible.
$@
|
|
|
|
|
Saurabh.abhyankar wrote: Please help us to resolve above critical issue as soon as possible. You've got the wrong forum; this is a sysadmin thing. Secondly, we're volunteers. If you "need" support now, you can contact Microsoft.
ASAP means to me "skip this".
Saurabh.abhyankar wrote: After lot of investigation we found that our application is unable to decrypt previously encrypted XML data stored in Database. Does it throw an exception? Does it return garbage? Can you reproduce it?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Saurabh.abhyankar wrote: After lot of RND we found that one of the critical windows auto update installed on 09/10/2013 or 10/10/2013 (attached as a sample) is causing the problem. Then why aren't you talking to Microsoft about it?
Veni, vidi, abiit domum
|
|
|
|
|
Hi, we have a requirement to develop an User Interface which should be able to deploy in Linux as well as Windows XP/7. Please can you help me in with some tips.
|
|
|
|