Which one is "better" code snippet? [closed] - vb.net

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 13 years ago.
Which code snippet is better? and How? ['Better' on the basis of, readability, debug, code standards etc...,]
Dim Name As String = Employee.Name
or
Dim Name As String
Name = Employee.Name

Combining declaration and assignement is generally thought to be the best approach (your first example)

Well as they are both equivalent and both very simple I would expect the compiler to reduce them to the same thing so neither is really better.
Personally I feel the second has its advantages in that you can create several variables of one type in one line of code and then initialise them one after the other which for readable code is my preference. But if you only have one variable to initialise then the first is nice and concise as well.

As long as there is no null / empty or content checking between declaration and assignment, I prefer option number 1. Easier to read and less clutter.

Related

Looking for a collection of data with no clear pattern [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am trying to run a query to search for a collection of data with no clear pattern, in fact it conflicts with an existing pattern.
The solution I have in mind is to run the query with an AND for all the data that does have a pattern(let's assume every other record follows pattern, except for what i am looking for, so it's basically scattered with no clear way of putting it together) and them what's left over, can be retrieved and displayed.
The solution I have in mind is to run the query with an AND for all
the data that does have a pattern
Well, if you want to find everything that doesn't follow any pattern just enclose all the patterns within brackets and combine with boolean AND.
Then just put a NOT outside the brackets.
Example:
select * from data where
NOT (CONDITION1 AND CONDITION2 AND...AND CONDITION_N)
I imagine your conditions are statements such as string comparisons using like (and wildcards) in addition to arithmetic comparisons.

SQL does replace and CAST on select affect the Database? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am creating a view and I was asked to do a 'replace' and a 'cast', so as an example:
SELECT CAST(qtyshipped AS INT) AS 'QTYShipped', REPLACE(itemval,'.','')
FROM Database
Within the view, should not actually change the information in the database but just in the query correct? (It works perfectly in my sandbox server but i just want to confirm)
Not a dumb question at all. And the answer is yes, it only changes the result of the query, the underlying data will remain the same.
That is already a good query. But I need to tell some points with you.
REPLACE function is case-sensitive. Although I've seen in your code that you are only replacing period.
Why is your column qtyshipped is not in numeric type? You should have change that into numeric. So you won't need casting which may lower the performance.
It will not affect your database since your are only executing SELECT not UPDATE.

Objective-C: Generic Pointers in practice [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Namaste! How often do you, experienced guys using generic pointers in daily routine and what's the common purpose for generic pointers in cocoa-touch development?
EDIT
A variable declared as a pointer to void is a generic pointer.
There's such thing. It may be set to an address of any variable type. I just want to know how the people use this kind of pointers in real life coding.
P.S Thank you for down voting.
There are fewer and fewer cases where void* is appropriate in ObjC. They're still used for some things like context pointers for KVO, but with the addition of ARC they're a pain to use even for that. Basically, if you need to ask when you would use a void*, you probably shouldn't use a void*. They're a little more common in the callbacks of Core frameworks, again usually for context pointers.
But to the question, "How often do you... [use void*] ... in daily routine," the answer is "very seldom, and as little as possible."

Keeping clear of SQL injections [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
If I make sure only alpha-numerical characters are used in queries I should be free of any SQL injections, right?
SQL Injection Prevention CheatSheet
Bullet points:
Defense Option 1: Prepared Statements (Parameterized Queries)
...how all developers should first be taught how to write database queries.
Defense Option 2: Stored Procedures
...when implemented safely.
Defense Option 3: Escaping All User Supplied Input
...frail compared to using parameterized queries.
It's pretty difficult to write a useful query with only alpha-numeric characters. Use paramterized queries, don't look for a non-shortcut shortcut.
Technically, that's probably correct, since it would block using -- or similar trickery. Most platforms these days have much more robust methods for properly escaping input and keeping it from affecting the database in unintended ways, however.

RoR - How To Count & Display Comments [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm looking to have a count of the number of comments left under an article and display it on the index page beside that particular article - like the example here in red circles. Any suggestions as to how I might do this?
The picture is an example of what I'm trying to do, its not my site.
This sounds like a good candidate for Rails.cache. Every time you create a new comment simply increment that cache counter using the post id.
If the cache entry does not exist, do a simple article.comments.count (depends on your domain model of course) query and re-cache it.
Storing it in a cache is one idea, yes.
But storing it in a counter_cache column is probably a better idea. That way even if your server was restarted somehow you wouldn't loose the cached values. See http://guides.rubyonrails.org/association_basics.html, section 4.1.2.4.