Search Results

Search found 20859 results on 835 pages for 'little bobby tables'.

Page 1/835 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • TechEd 2012: A Little Cloud And Too Little Windows Phone

    - by Tim Murphy
    It is Monday afternoon and the last couple of sessions have been disappointing.  I started out in the Nokia: Learning to Tile session.  I guess I should have read the summary more closely because it turned out to be more of a Nokia/WP7 history and sales pitch. “I’m outa here!” I made a quick venue change and now we are learning about Private Cloud Architecture.  The topic and the material were very informative.  The speaker even had a couple of quotable statements. The first quote was “You can trust me … I’m a doctor”.  The second was a new acronym (at least for me): CAVE – committee against virtually everything.  I am sure I have dealt with them more than once in my career. Unfortunately he didn’t just have a doctorate, the presentation was overdone like a medical journal.  While I didn’t enjoy the presentation, I am looking forward to getting my hands on the slides to review. Here is looking forward to the next sessions. del.icio.us Tags: Windows Phone,Cloud,Architecture

    Read the article

  • C#/.NET Little Wonders: A Redux

    - by James Michael Hare
    I gave my Little Wonders presentation to the Topeka Dot Net Users' Group today, so re-posting the links to all the previous posts for them. The Presentation: C#/.NET Little Wonders: A Presentation The Original Trilogy: C#/.NET Five Little Wonders (part 1) C#/.NET Five More Little Wonders (part 2) C#/.NET Five Final Little Wonders (part 3) The Subsequent Sequels: C#/.NET Little Wonders: ToDictionary() and ToList() C#/.NET Little Wonders: DateTime is Packed With Goodies C#/.NET Little Wonders: Fun With Enum Methods C#/.NET Little Wonders: Cross-Calling Constructors C#/.NET Little Wonders: Constraining Generics With Where Clause C#/.NET Little Wonders: Comparer<T>.Default C#/.NET Little Wonders: The Useful (But Overlooked) Sets The Concurrent Wonders: C#/.NET Little Wonders: The Concurrent Collections (1 of 3) - ConcurrentQueue and ConcurrentStack C#/.NET Little Wonders: The Concurrent Collections (2 of 3) - ConcurrentDictionary Tweet   Technorati Tags: .NET,C#,Little Wonders

    Read the article

  • C#/.NET Little Wonders: Getting Caller Information

    - by James Michael Hare
    Originally posted on: http://geekswithblogs.net/BlackRabbitCoder/archive/2013/07/25/c.net-little-wonders-getting-caller-information.aspx Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. There are times when it is desirable to know who called the method or property you are currently executing.  Some applications of this could include logging libraries, or possibly even something more advanced that may server up different objects depending on who called the method. In the past, we mostly relied on the System.Diagnostics namespace and its classes such as StackTrace and StackFrame to see who our caller was, but now in C# 5, we can also get much of this data at compile-time. Determining the caller using the stack One of the ways of doing this is to examine the call stack.  The classes that allow you to examine the call stack have been around for a long time and can give you a very deep view of the calling chain all the way back to the beginning for the thread that has called you. You can get caller information by either instantiating the StackTrace class (which will give you the complete stack trace, much like you see when an exception is generated), or by using StackFrame which gets a single frame of the stack trace.  Both involve examining the call stack, which is a non-trivial task, so care should be done not to do this in a performance-intensive situation. For our simple example let's say we are going to recreate the wheel and construct our own logging framework.  Perhaps we wish to create a simple method Log which will log the string-ified form of an object and some information about the caller.  We could easily do this as follows: 1: static void Log(object message) 2: { 3: // frame 1, true for source info 4: StackFrame frame = new StackFrame(1, true); 5: var method = frame.GetMethod(); 6: var fileName = frame.GetFileName(); 7: var lineNumber = frame.GetFileLineNumber(); 8: 9: // we'll just use a simple Console write for now 10: Console.WriteLine("{0}({1}):{2} - {3}", 11: fileName, lineNumber, method.Name, message); 12: } So, what we are doing here is grabbing the 2nd stack frame (the 1st is our current method) using a 2nd argument of true to specify we want source information (if available) and then taking the information from the frame.  This works fine, and if we tested it out by calling from a file such as this: 1: // File c:\projects\test\CallerInfo\CallerInfo.cs 2:  3: public class CallerInfo 4: { 5: Log("Hello Logger!"); 6: } We'd see this: 1: c:\projects\test\CallerInfo\CallerInfo.cs(5):Main - Hello Logger! This works well, and in fact CallStack and StackFrame are still the best ways to examine deeper into the call stack.  But if you only want to get information on the caller of your method, there is another option… Determining the caller at compile-time In C# 5 (.NET 4.5) they added some attributes that can be supplied to optional parameters on a method to receive caller information.  These attributes can only be applied to methods with optional parameters with explicit defaults.  Then, as the compiler determines who is calling your method with these attributes, it will fill in the values at compile-time. These are the currently supported attributes available in the  System.Runtime.CompilerServices namespace": CallerFilePathAttribute – The path and name of the file that is calling your method. CallerLineNumberAttribute – The line number in the file where your method is being called. CallerMemberName – The member that is calling your method. So let’s take a look at how our Log method would look using these attributes instead: 1: static int Log(object message, 2: [CallerMemberName] string memberName = "", 3: [CallerFilePath] string fileName = "", 4: [CallerLineNumber] int lineNumber = 0) 5: { 6: // we'll just use a simple Console write for now 7: Console.WriteLine("{0}({1}):{2} - {3}", 8: fileName, lineNumber, memberName, message); 9: } Again, calling this from our sample Main would give us the same result: 1: c:\projects\test\CallerInfo\CallerInfo.cs(5):Main - Hello Logger! However, though this seems the same, there are a few key differences. First of all, there are only 3 supported attributes (at this time) that give you the file path, line number, and calling member.  Thus, it does not give you as rich of detail as a StackFrame (which can give you the calling type as well and deeper frames, for example).  Also, these are supported through optional parameters, which means we could call our new Log method like this: 1: // They're defaults, why not fill 'em in 2: Log("My message.", "Some member", "Some file", -13); In addition, since these attributes require optional parameters, they cannot be used in properties, only in methods. These caveats aside, they do let you get similar information inside of methods at a much greater speed!  How much greater?  Well lets crank through 1,000,000 iterations of each.  instead of logging to console, I’ll return the formatted string length of each.  Doing this, we get: 1: Time for 1,000,000 iterations with StackTrace: 5096 ms 2: Time for 1,000,000 iterations with Attributes: 196 ms So you see, using the attributes is much, much faster!  Nearly 25x faster in fact.  Summary There are a few ways to get caller information for a method.  The StackFrame allows you to get a comprehensive set of information spanning the whole call stack, but at a heavier cost.  On the other hand, the attributes allow you to quickly get at caller information baked in at compile-time, but to do so you need to create optional parameters in your methods to support it. Technorati Tags: Little Wonders,CSharp,C#,.NET,StackFrame,CallStack,CallerFilePathAttribute,CallerLineNumberAttribute,CallerMemberName

    Read the article

  • Removing Little Snitch completely (Mac OS X Snow Leopard)

    - by Mathias Bynens
    I uninstalled Little Snitch months ago. Or so, I thought. When opening Console.app, I see something like this: Here’s a textual log: 21/11/09 22:05:31 com.apple.launchd[1] (at.obdev.littlesnitchd[10045]) Exited with exit code: 1 21/11/09 22:05:31 com.apple.launchd[1] (at.obdev.littlesnitchd) Throttling respawn: Will start in 10 seconds 21/11/09 22:05:33 Little Snitch UIAgent[10046] 2.0.4.385: m65968c1c 21/11/09 22:05:33 Little Snitch UIAgent[10046] 2.0.4.385: m579328b9 21/11/09 22:05:33 Little Snitch UIAgent[10046] 2.0.4.385: m41531ded 21/11/09 22:05:33 com.apple.launchd.peruser.501[170] (at.obdev.LittleSnitchUIAgent) Throttling respawn: Will start in 10 seconds 21/11/09 22:05:41 com.apple.launchd[1] (at.obdev.littlesnitchd[10049]) Exited with exit code: 1 21/11/09 22:05:41 com.apple.launchd[1] (at.obdev.littlesnitchd) Throttling respawn: Will start in 10 seconds 21/11/09 22:05:43 Little Snitch UIAgent[10050] 2.0.4.385: m65968c1c 21/11/09 22:05:43 Little Snitch UIAgent[10050] 2.0.4.385: m579328b9 21/11/09 22:05:43 Little Snitch UIAgent[10050] 2.0.4.385: m41531ded 21/11/09 22:05:43 com.apple.launchd.peruser.501[170] (at.obdev.LittleSnitchUIAgent) Throttling respawn: Will start in 10 seconds Spotlight searches for ‘little snitch’ or ‘littlesnitch’ yield no results. Yet, it seems like I didn’t get rid of Little Snitch entirely, since it’s still using up my CPU. Any ideas?

    Read the article

  • Temporary Tables in Stored Procedures

    - by Paul White
    Ask anyone what the primary advantage of temporary tables over table variables is, and the chances are they will say that temporary tables support statistics and table variables do not. This is true, of course; even the indexes that enforce PRIMARY KEY and UNIQUE constraints on table variables do not have populated statistics associated with them, and it is not possible to manually create statistics or non-constraint indexes on table variables. Intuitively, then, any query that has alternative execution...(read more)

    Read the article

  • Django: Setting up database code tables (aka reference tables, domain tables)?

    - by User
    Often times applications will need some database code tables (aka reference tables or domain tables or lookup tables). Suppose I have a model class called Status with a field called name that could hold values like: Canceled Pending InProgress Complete Where and at what point would I setup these values in Django? Its like a one time operation to setup these values in the database. Infrequently, these values could be added to.

    Read the article

  • Substituting Java for Groovy Little By Little

    - by yar
    I have been checking out Groovy a bit and I feel that moving a Java program to Groovy little by little -- grabbing a class and making it a Groovy class, then converting the method guts a bit at a time -- might be a relatively sane way to take advantage of some of the Groovy language features. I would also do new classes in Groovy. Questions: Is this a reasonable way to convert? Can I keep all of my public methods and and fields in Java? Groovy is "just" a superset, right? What kinds of things would you not do in Groovy, but prefer Java instead?

    Read the article

  • Little Wheel Is An Atmospheric and Engaging Point-and-Click Adventure

    - by Jason Fitzpatrick
    If you’re a fan of the resurgence of highly stylized and atmospheric adventure games–such as Spirit, World of Goo, and the like–you’ll definitely want to check out this well executed, free, and more than a little bit charming browser-based game. Little Wheel is set in a world of robots where, 10,000 years ago, a terrible accident at the central power plant left all the robots without power. The entire robot world went into a deep sleep and now, thanks to a freak lightning strike, one little robot has woken up. Your job, as that little robot, is to navigate the world of Little Wheel and help bring it back to life. Hit up the link below to play the game for free–the quality of the visual and audio design make going full screen and turning the speakers on a must. Little Wheel [via Freeware Genuis] How to Make Your Laptop Choose a Wired Connection Instead of Wireless HTG Explains: What Is Two-Factor Authentication and Should I Be Using It? HTG Explains: What Is Windows RT and What Does It Mean To Me?

    Read the article

  • What's the closest equivalent of Little Snitch (Mac program) on Windows?

    - by Charles Scowcroft
    I'm using Windows 7 and would like to have a feature like Little Snitch on the Mac that alerts you whenever a program on your computer makes an outgoing connection. Description of Little Snitch from its website: Little Snitch informs you whenever a program attempts to establish an outgoing Internet connection. You can then choose to allow or deny this connection, or define a rule how to handle similar, future connection attempts. This reliably prevents private data from being sent out without your knowledge. Little Snitch runs inconspicuously in the background and it can also detect network related activity of viruses, trojans and other malware. Little Snitch provides flexible configuration options, allowing you to grant specific permissions to your trusted applications or to prevent others from establishing particular Internet connections at all. So you will only be warned in those cases that really need your attention. Is there a program like Little Snitch for Windows?

    Read the article

  • little oh notation as the limit of n goes to infinity

    - by Tony
    Hi all, I'm just trying to understand how in little o notation this is true: f(n)/g(n) as n goes to infinity = infinity? Can someone explain that to me? I do get the idea that f(n) = o(g(n)) means that f(n) grows no faster then cg(n) for all constants c 0. I just don't get the bit in bold above.

    Read the article

  • Database warehouse design: fact tables and dimension tables

    - by morpheous
    I am building a poor man's data warehouse using a RDBMS. I have identified the key 'attributes' to be recorded as: sex (true/false) demographic classification (A, B, C etc) place of birth date of birth weight (recorded daily): The fact that is being recorded My requirements are to be able to run 'OLAP' queries that allow me to: 'slice and dice' 'drill up/down' the data and generally, be able to view the data from different perspectives After reading up on this topic area, the general consensus seems to be that this is best implemented using dimension tables rather than normalized tables. Assuming that this assertion is true (i.e. the solution is best implemented using fact and dimension tables), I would like to seek some help in the design of these tables. 'Natural' (or obvious) dimensions are: Date dimension Geographical location Which have hierarchical attributes. However, I am struggling with how to model the following fields: sex (true/false) demographic classification (A, B, C etc) The reason I am struggling with these fields is that: They have no obvious hierarchical attributes which will aid aggregation (AFAIA) - which suggest they should be in a fact table They are mostly static or very rarely change - which suggests they should be in a dimension table. Maybe the heuristic I am using above is too crude? I will give some examples on the type of analysis I would like to carryout on the data warehouse - hopefully that will clarify things further. I would like to aggregate and analyze the data by sex and demographic classification - e.g. answer questions like: How does male and female weights compare across different demographic classifications? Which demographic classification (male AND female), show the most increase in weight this quarter. etc. Can anyone clarify whether sex and demographic classification are part of the fact table, or whether they are (as I suspect) dimension tables.? Also assuming they are dimension tables, could someone elaborate on the table structures (i.e. the fields)? The 'obvious' schema: CREATE TABLE sex_type (is_male int); CREATE TABLE demographic_category (id int, name varchar(4)); may not be the correct one.

    Read the article

  • Database warehoue design: fact tables and dimension tables

    - by morpheous
    I am building a poor man's data warehouse using a RDBMS. I have identified the key 'attributes' to be recorded as: sex (true/false) demographic classification (A, B, C etc) place of birth date of birth weight (recorded daily): The fact that is being recorded My requirements are to be able to run 'OLAP' queries that allow me to: 'slice and dice' 'drill up/down' the data and generally, be able to view the data from different perspectives After reading up on this topic area, the general consensus seems to be that this is best implemented using dimension tables rather than normalized tables. Assuming that this assertion is true (i.e. the solution is best implemented using fact and dimension tables), I would like to see some help in the design of these tables. 'Natural' (or obvious) dimensions are: Date dimension Geographical location Which have hierarchical attributes. However, I am struggling with how to model the following fields: sex (true/false) demographic classification (A, B, C etc) The reason I am struggling with these fields is that: They have no obvious hierarchical attributes which will aid aggregation (AFAIA) - which suggest they should be in a fact table They are mostly static or very rarely change - which suggests they should be in a dimension table. Maybe the heuristic I am using above is too crude? I will give some examples on the type of analysis I would like to carryout on the data warehouse - hopefully that will clarify things further. I would like to aggregate and analyze the data by sex and demographic classification - e.g. answer questions like: How does male and female weights compare across different demographic classifications? Which demographic classification (male AND female), show the most increase in weight this quarter. etc. Can anyone clarify whether sex and demographic classification are part of the fact table, or whether they are (as I suspect) dimension tables.? Also assuming they are dimension tables, could someone elaborate on the table structures (i.e. the fields)? The 'obvious' schema: CREATE TABLE sex_type (is_male int); CREATE TABLE demographic_category (id int, name varchar(4)); may not be the correct one.

    Read the article

  • SQL Server 2000 tables

    - by user40766
    We currently have an SQL Server 2000 database with one table containing data for multiple users. The data is keyed by memberid which is an integer field. The table has a clustered index on memberid. The table is now about 200 million rows. Indexing and maintenance are becoming issues. We are debating splitting the table into one table per user model. This would imply that we would end up with a very large number of tables potentially upto the 2,147,483,647, considering just positive values. My questions: Does anyone have any experience with a SQL Server (2000/2005) installation with millions of tables? What are the implications of this architecture with regards to maintenance and access using Query Analyzer, Enterprise Manager etc. What are the implications to having such a large number of indexes in a database instance. All comments are appreciated. Thanks

    Read the article

  • If tables are so evil, why does joomla use tables for its layout?

    - by DMin
    When you create a template you don't use tables. but when joomla rendereds the page, there are at least 4 places where tables are used to structure the content. Does this tell you something about tables or the fact that the joomla community should invest more time and learn how to code css or just the fact that tables are needed when you don't know what css is going to be throw in later(which probably means they are of some use)?

    Read the article

  • retrieve data from multiple tables referencing some tables in mysql

    - by I Like PHP
    i have 10 tables have innoDB engine 1. one is state_table which attributes are state_id and state_name 2. another table city_table which attributes are city_id and city_name 3. one more table permit_table which attribute is p_id above city_id,state_id and permit_id is references to rest of 7 tables. each table having state_id, city_id and permit_id referencing above tables now i want to extract all tables data with their respective city name and state name ( each tables may have different city id and state id) i m using below mysql query( i know it's very length way.... ) . please tell me how to do it with optimized method? SELECT p.*,cp.city_name,sp.state_name, o.*,co.city_name,so.state_name, t.*,ct.city_name,st.state_name, th.*,cth.city_name,sth.state_name, f.*,cf.city_name,sf.state_name .......so on................ .......so on................ ............................ FROM permit_table p JOIN table_city cp ON cp.city_id=p.city_id JOIN table_state sp ON sp.state_id=p.state_id JOIN table_one o ON o.permit_id=p.permit_id JOIN table_city co ON co.city_id=o.city_id JOIN table_state so ON so.state_id=o.state_id JOIN table_two t ON t.permit_id=p.permit_id JOIN table_city ct ON ct.city_id=t.city_id JOIN table_state st ON st.state_id=t.state_id JOIN table_three th ON th.permit_id=p.permit_id JOIN table_city cth ON cth.city_id=th.city_id JOIN table_state sth ON sth.state_id=th.state_id JOIN table_four f ON f.permit_id=p.permit_id JOIN table_city cf ON cf.city_id=f.city_id JOIN table_state sf ON sf.state_id=f.state_id ................so on......................... ................so on......................... .............................................. WHERE p.permit_id=base64_encode(mysql_real_escape_string($_GET[pid])); Thanks For help me always.

    Read the article

  • retrive data from multiple tables referencing some tables in mysql

    - by I Like PHP
    i have 10 tables have innoDB engine 1. one is state_table which attributes are state_id and state_name 2. another table city_table which attributes are city_id and city_name 3. one more table permit_table which attribute is p_id above city_id,state_id and permit_id is references to rest of 7 tables. each table having state_id, city_id and permit_id referencing above tables now i want to extract all tables data with their respective city name and state name ( each tables may have different city id and state id) i m using below mysql query( i know it's very length way.... ) . please tell me how to do it with optimized method? SELECT p.*,cp.city_name,sp.state_name, o.*,co.city_name,so.state_name, t.*,ct.city_name,st.state_name, th.*,cth.city_name,sth.state_name, f.*,cf.city_name,sf.state_name .......so on................ .......so on................ ............................ FROM permit_table p JOIN table_city cp ON cp.city_id=p.city_id JOIN table_state sp ON sp.state_id=p.state_id JOIN table_one o ON o.permit_id=p.permit_id JOIN table_city co ON co.city_id=o.city_id JOIN table_state so ON so.state_id=o.state_id JOIN table_two t ON t.permit_id=p.permit_id JOIN table_city ct ON ct.city_id=t.city_id JOIN table_state st ON st.state_id=t.state_id JOIN table_three th ON th.permit_id=p.permit_id JOIN table_city cth ON cth.city_id=th.city_id JOIN table_state sth ON sth.state_id=th.state_id JOIN table_four f ON f.permit_id=p.permit_id JOIN table_city cf ON cf.city_id=f.city_id JOIN table_state sf ON sf.state_id=f.state_id ................so on......................... ................so on......................... .............................................. WHERE p.permit_id=base64_encode(mysql_real_escape_string($_GET[pid]); Thanks For help me always.

    Read the article

  • C#/.NET Little Wonders: The Nullable static class

    - by James Michael Hare
    Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Today we’re going to look at an interesting Little Wonder that can be used to mitigate what could be considered a Little Pitfall.  The Little Wonder we’ll be examining is the System.Nullable static class.  No, not the System.Nullable<T> class, but a static helper class that has one useful method in particular that we will examine… but first, let’s look at the Little Pitfall that makes this wonder so useful. Little Pitfall: Comparing nullable value types using <, >, <=, >= Examine this piece of code, without examining it too deeply, what’s your gut reaction as to the result? 1: int? x = null; 2:  3: if (x < 100) 4: { 5: Console.WriteLine("True, {0} is less than 100.", 6: x.HasValue ? x.ToString() : "null"); 7: } 8: else 9: { 10: Console.WriteLine("False, {0} is NOT less than 100.", 11: x.HasValue ? x.ToString() : "null"); 12: } Your gut would be to say true right?  It would seem to make sense that a null integer is less than the integer constant 100.  But the result is actually false!  The null value is not less than 100 according to the less-than operator. It looks even more outrageous when you consider this also evaluates to false: 1: int? x = null; 2:  3: if (x < int.MaxValue) 4: { 5: // ... 6: } So, are we saying that null is less than every valid int value?  If that were true, null should be less than int.MinValue, right?  Well… no: 1: int? x = null; 2:  3: // um... hold on here, x is NOT less than min value? 4: if (x < int.MinValue) 5: { 6: // ... 7: } So what’s going on here?  If we use greater than instead of less than, we see the same little dilemma: 1: int? x = null; 2:  3: // once again, null is not greater than anything either... 4: if (x > int.MinValue) 5: { 6: // ... 7: } It turns out that four of the comparison operators (<, <=, >, >=) are designed to return false anytime at least one of the arguments is null when comparing System.Nullable wrapped types that expose the comparison operators (short, int, float, double, DateTime, TimeSpan, etc.).  What’s even odder is that even though the two equality operators (== and !=) work correctly, >= and <= have the same issue as < and > and return false if both System.Nullable wrapped operator comparable types are null! 1: DateTime? x = null; 2: DateTime? y = null; 3:  4: if (x <= y) 5: { 6: Console.WriteLine("You'd think this is true, since both are null, but it's not."); 7: } 8: else 9: { 10: Console.WriteLine("It's false because <=, <, >, >= don't work on null."); 11: } To make matters even more confusing, take for example your usual check to see if something is less than, greater to, or equal: 1: int? x = null; 2: int? y = 100; 3:  4: if (x < y) 5: { 6: Console.WriteLine("X is less than Y"); 7: } 8: else if (x > y) 9: { 10: Console.WriteLine("X is greater than Y"); 11: } 12: else 13: { 14: // We fall into the "equals" assumption, but clearly null != 100! 15: Console.WriteLine("X is equal to Y"); 16: } Yes, this code outputs “X is equal to Y” because both the less-than and greater-than operators return false when a Nullable wrapped operator comparable type is null.  This violates a lot of our assumptions because we assume is something is not less than something, and it’s not greater than something, it must be equal.  So keep in mind, that the only two comparison operators that work on Nullable wrapped types where at least one is null are the equals (==) and not equals (!=) operators: 1: int? x = null; 2: int? y = 100; 3:  4: if (x == y) 5: { 6: Console.WriteLine("False, x is null, y is not."); 7: } 8:  9: if (x != y) 10: { 11: Console.WriteLine("True, x is null, y is not."); 12: } Solution: The Nullable static class So we’ve seen that <, <=, >, and >= have some interesting and perhaps unexpected behaviors that can trip up a novice developer who isn’t expecting the kinks that System.Nullable<T> types with comparison operators can throw.  How can we easily mitigate this? Well, obviously, you could do null checks before each check, but that starts to get ugly: 1: if (x.HasValue) 2: { 3: if (y.HasValue) 4: { 5: if (x < y) 6: { 7: Console.WriteLine("x < y"); 8: } 9: else if (x > y) 10: { 11: Console.WriteLine("x > y"); 12: } 13: else 14: { 15: Console.WriteLine("x == y"); 16: } 17: } 18: else 19: { 20: Console.WriteLine("x > y because y is null and x isn't"); 21: } 22: } 23: else if (y.HasValue) 24: { 25: Console.WriteLine("x < y because x is null and y isn't"); 26: } 27: else 28: { 29: Console.WriteLine("x == y because both are null"); 30: } Yes, we could probably simplify this logic a bit, but it’s still horrendous!  So what do we do if we want to consider null less than everything and be able to properly compare Nullable<T> wrapped value types? The key is the System.Nullable static class.  This class is a companion class to the System.Nullable<T> class and allows you to use a few helper methods for Nullable<T> wrapped types, including a static Compare<T>() method of the. What’s so big about the static Compare<T>() method?  It implements an IComparer compatible comparison on Nullable<T> types.  Why do we care?  Well, if you look at the MSDN description for how IComparer works, you’ll read: Comparing null with any type is allowed and does not generate an exception when using IComparable. When sorting, null is considered to be less than any other object. This is what we probably want!  We want null to be less than everything!  So now we can change our logic to use the Nullable.Compare<T>() static method: 1: int? x = null; 2: int? y = 100; 3:  4: if (Nullable.Compare(x, y) < 0) 5: { 6: // Yes! x is null, y is not, so x is less than y according to Compare(). 7: Console.WriteLine("x < y"); 8: } 9: else if (Nullable.Compare(x, y) > 0) 10: { 11: Console.WriteLine("x > y"); 12: } 13: else 14: { 15: Console.WriteLine("x == y"); 16: } Summary So, when doing math comparisons between two numeric values where one of them may be a null Nullable<T>, consider using the System.Nullable.Compare<T>() method instead of the comparison operators.  It will treat null less than any value, and will avoid logic consistency problems when relying on < returning false to indicate >= is true and so on. Tweet   Technorati Tags: C#,C-Sharp,.NET,Little Wonders,Little Pitfalls,Nulalble

    Read the article

  • C#/.NET Little Wonders: Static Char Methods

    - by James Michael Hare
    Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Often times in our code we deal with the bigger classes and types in the BCL, and occasionally forgot that there are some nice methods on the primitive types as well.  Today we will discuss some of the handy static methods that exist on the char (the C# alias of System.Char) type. The Background I was examining a piece of code this week where I saw the following: 1: // need to get the 5th (offset 4) character in upper case 2: var type = symbol.Substring(4, 1).ToUpper(); 3:  4: // test to see if the type is P 5: if (type == "P") 6: { 7: // ... do something with P type... 8: } Is there really any error in this code?  No, but it still struck me wrong because it is allocating two very short-lived throw-away strings, just to store and manipulate a single char: The call to Substring() generates a new string of length 1 The call to ToUpper() generates a new upper-case version of the string from Step 1. In my mind this is similar to using ToUpper() to do a case-insensitive compare: it isn’t wrong, it’s just much heavier than it needs to be (for more info on case-insensitive compares, see #2 in 5 More Little Wonders). One of my favorite books is the C++ Coding Standards: 101 Rules, Guidelines, and Best Practices by Sutter and Alexandrescu.  True, it’s about C++ standards, but there’s also some great general programming advice in there, including two rules I love:         8. Don’t Optimize Prematurely         9. Don’t Pessimize Prematurely We all know what #8 means: don’t optimize when there is no immediate need, especially at the expense of readability and maintainability.  I firmly believe this and in the axiom: it’s easier to make correct code fast than to make fast code correct.  Optimizing code to the point that it becomes difficult to maintain often gains little and often gives you little bang for the buck. But what about #9?  Well, for that they state: “All other things being equal, notably code complexity and readability, certain efficient design patterns and coding idioms should just flow naturally from your fingertips and are no harder to write then the pessimized alternatives. This is not premature optimization; it is avoiding gratuitous pessimization.” Or, if I may paraphrase: “where it doesn’t increase the code complexity and readability, prefer the more efficient option”. The example code above was one of those times I feel where we are violating a tacit C# coding idiom: avoid creating unnecessary temporary strings.  The code creates temporary strings to hold one char, which is just unnecessary.  I think the original coder thought he had to do this because ToUpper() is an instance method on string but not on char.  What he didn’t know, however, is that ToUpper() does exist on char, it’s just a static method instead (though you could write an extension method to make it look instance-ish). This leads me (in a long-winded way) to my Little Wonders for the day… Static Methods of System.Char So let’s look at some of these handy, and often overlooked, static methods on the char type: IsDigit(), IsLetter(), IsLetterOrDigit(), IsPunctuation(), IsWhiteSpace() Methods to tell you whether a char (or position in a string) belongs to a category of characters. IsLower(), IsUpper() Methods that check if a char (or position in a string) is lower or upper case ToLower(), ToUpper() Methods that convert a single char to the lower or upper equivalent. For example, if you wanted to see if a string contained any lower case characters, you could do the following: 1: if (symbol.Any(c => char.IsLower(c))) 2: { 3: // ... 4: } Which, incidentally, we could use a method group to shorten the expression to: 1: if (symbol.Any(char.IsLower)) 2: { 3: // ... 4: } Or, if you wanted to verify that all of the characters in a string are digits: 1: if (symbol.All(char.IsDigit)) 2: { 3: // ... 4: } Also, for the IsXxx() methods, there are overloads that take either a char, or a string and an index, this means that these two calls are logically identical: 1: // check given a character 2: if (char.IsUpper(symbol[0])) { ... } 3:  4: // check given a string and index 5: if (char.IsUpper(symbol, 0)) { ... } Obviously, if you just have a char, then you’d just use the first form.  But if you have a string you can use either form equally well. As a side note, care should be taken when examining all the available static methods on the System.Char type, as some seem to be redundant but actually have very different purposes.  For example, there are IsDigit() and IsNumeric() methods, which sound the same on the surface, but give you different results. IsDigit() returns true if it is a base-10 digit character (‘0’, ‘1’, … ‘9’) where IsNumeric() returns true if it’s any numeric character including the characters for ½, ¼, etc. Summary To come full circle back to our opening example, I would have preferred the code be written like this: 1: // grab 5th char and take upper case version of it 2: var type = char.ToUpper(symbol[4]); 3:  4: if (type == 'P') 5: { 6: // ... do something with P type... 7: } Not only is it just as readable (if not more so), but it performs over 3x faster on my machine:    1,000,000 iterations of char method took: 30 ms, 0.000050 ms/item.    1,000,000 iterations of string method took: 101 ms, 0.000101 ms/item. It’s not only immediately faster because we don’t allocate temporary strings, but as an added bonus there less garbage to collect later as well.  To me this qualifies as a case where we are using a common C# performance idiom (don’t create unnecessary temporary strings) to make our code better. Technorati Tags: C#,CSharp,.NET,Little Wonders,char,string

    Read the article

  • A Trio of Presentations: Little Wonders, StyleCop, and LINQ/Lambdas

    - by James Michael Hare
    This week is a busy week for me.  First of all I’m giving another presentation on a LINQ/Lambda primer for the rest of the developers in my company.  Of Lambdas and LINQ View more presentations from BlackRabbitCoder Then this Saturday the 25th of June I’ll be reprising my Little Wonders presentation for the Kansas City Developers Camp.  If you are in the area I highly recommend attending and seeing the other great presentations as well.  Their link is here. Little Wonders View more presentations from BlackRabbitCoder Finally, this Monday the 27th I’ll be speaking at the Saint Louis .NET Users group, giving my Automating Code Standards Using StyleCop and FxCop presentation.  If you are in the Saint Louis area stop by!  There’s two other simultaneous presentations as well if they’re more suited to your interests.  The link for the SLDNUG is here. Automating C# Coding Standards using StyleCop and FxCop View more presentations from BlackRabbitCoder Tweet Technorati Tags: C#,.NET,LINQ,Lambda,StyleCop,FxCop,Little Wonders

    Read the article

  • Why not use tables for layout in HTML?

    - by Bno
    It seems to be the general opinion that tables should not be used for layout in HTML. Why? I have never (or rarely to be honest) seen good arguments for this. The usual answers are: It's good to separate content from layoutBut this is a fallacious argument; Cliche Thinking. I guess it's true that using the table element for layout has little to do with tabular data. So what? Does my boss care? Do my users care?Perhaps me or my fellow developers who have to maintain a web page care... Is a table less maintainable? I think using a table is easier than using divs and CSS.By the way... why is using a div or a span good separation of content from layout and a table not? Getting a good layout with only divs often requires a lot of nested divs. Readability of the codeI think it's the other way around. Most people understand html, few understand CSS. It's better for SEO not to use tablesWhy? Can anybody show some evidence that it is? Or a statement from Google that tables are discouraged from an SEO perspective? Tables are slower.An extra tbody element has to be inserted. This is peanuts for modern web browsers. Show me some benchmarks where the use of a table significantly slows down a page. A layout overhaul is easier without tables, see css Zen Garden.Most web sites that need an upgrade need new content (html) as well. Scenarios where a new version of a web site only needs a new CSS file are not very likely. Zen Garden is a nice web site, but a bit theoretical. Not to mention its misuse of CSS. I am really interested in good arguments to use divs + CSS instead of tables.

    Read the article

  • In Oracle 10g, how do I see tables in schemes other than system

    - by Yasir Arsanukaev
    In the hr schema there's a table emloyees, I can query data from it specifying it implicitly SELECT count(*) FROM hr.employees while logged in as system, but when I navigate to Home-Object Browser in the browser I can't see the table employees and other tables in other schemas. Can I manage tables in schemas other than system while logged in as system? Maybe there's some setting which enables me to group tables by schema. My Oracle Database version is 10.2.0.1 Express Edition. IIRC I could see all tables in Oracle Database 10.1.x.y. Thanks.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >