Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
R

Rotted Frog

@Rotted Frog
About
Posts
18
Topics
5
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • What position is the letter A? Let's use a lookup table!
    R Rotted Frog

    And it gets better... Just noticed the next class on from that one:

    public class ZeroBasedAlphabetPositionMap
    {
    private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

    static ZeroBasedAlphabetPositionMap()
    {
        alphabet.Add('A', 0);
        alphabet.Add('B', 1);
        alphabet.Add('C', 2);
        alphabet.Add('D', 3);
        alphabet.Add('E', 4);
        alphabet.Add('F', 5);
        alphabet.Add('G', 6);
        alphabet.Add('H', 7);
        alphabet.Add('I', 8);
        alphabet.Add('J', 9);
        alphabet.Add('K', 10);
        alphabet.Add('L', 11);
        alphabet.Add('M', 12);
        alphabet.Add('N', 13);
        alphabet.Add('O', 14);
        alphabet.Add('P', 15);
        alphabet.Add('Q', 16);
        alphabet.Add('R', 17);
        alphabet.Add('S', 18);
        alphabet.Add('T', 19);
        alphabet.Add('U', 20);
        alphabet.Add('V', 21);
        alphabet.Add('W', 22);
        alphabet.Add('X', 23);
        alphabet.Add('Y', 24);
        alphabet.Add('Z', 25);
    
    }
    
    public static int Position(char letter)
    {
        return alphabet\[letter\];
    }
    

    }

    The Weird and The Wonderful ruby question

  • What position is the letter A? Let's use a lookup table!
    R Rotted Frog

    Well done. You get all the bonus points.

    The Weird and The Wonderful ruby question

  • What position is the letter A? Let's use a lookup table!
    R Rotted Frog

    That did have a point. It was actually quite a funny point.

    The Weird and The Wonderful ruby question

  • What position is the letter A? Let's use a lookup table!
    R Rotted Frog

    yes, we need to add 'a' to 'z' in as well. I'll assign it out to one of my team to fix immediately.

    The Weird and The Wonderful ruby question

  • What position is the letter A? Let's use a lookup table!
    R Rotted Frog

    Just found this gem hiding in a project I've just inherited. Fortunately it doesn't appear to be used.

    public class AlphabetPositionMap
    {
    private static Dictionary<char, int> alphabet = new Dictionary<char, int>();

    static AlphabetPositionMap()
    {
        alphabet.Add('A', 1);
        alphabet.Add('B', 2);
        alphabet.Add('C', 3);
        alphabet.Add('D', 4);
        alphabet.Add('E', 5);
        alphabet.Add('F', 6);
        alphabet.Add('G', 7);
        alphabet.Add('H', 8);
        alphabet.Add('I', 9);
        alphabet.Add('J', 10);
        alphabet.Add('K', 11);
        alphabet.Add('L', 12);
        alphabet.Add('M', 13);
        alphabet.Add('N', 14);
        alphabet.Add('O', 15);
        alphabet.Add('P', 16);
        alphabet.Add('Q', 17);
        alphabet.Add('R', 18);
        alphabet.Add('S', 19);
        alphabet.Add('T', 20);
        alphabet.Add('U', 21);
        alphabet.Add('V', 22);
        alphabet.Add('W', 23);
        alphabet.Add('X', 24);
        alphabet.Add('Y', 25);
        alphabet.Add('Z', 26);
    
    }
    
    public static int Position(char letter)
    {
        return alphabet\[letter\];
    }
    

    }

    Prizes awarded to anyone who can find a more pointless use of a lookup table.

    The Weird and The Wonderful ruby question

  • String Comparison
    R Rotted Frog

    Actually I completely disagree. == is not a major sin in this instance - it is fairly well understood that == is equivalent to an ordinal string comparison not an object equivalence. It is functionally equivalent to .Equals() and much more readable - I would pull up use of .Equals in a code review on the readability point. However the best option is to use String.Compare instead as this does proper culture sensitive comparisons.

    The Weird and The Wonderful code-review

  • String Comparison
    R Rotted Frog

    Another one found during code review. Constants changed to protect the innocent.

    If (name.ToUpper() == "CamelCasedName".ToUpper()) {...}

    The Weird and The Wonderful code-review

  • Special Case
    R Rotted Frog

    It's likely that compiler optimisations make it irrelevant in this case. But in the general case, she using ++i the value is copied into i after being calculated, then copied into the return variable. Using i+1 only copies it to the return variable (one less copy).

    The Weird and The Wonderful

  • Special Case
    R Rotted Frog

    Just a quick one, but amused me when I saw it in code today.

    if (i == 0)
    return 1;
    else
    return i + 1;

    The Weird and The Wonderful

  • IcoFX
    R Rotted Frog

    Greenfish Icon Editor[^] is another free and simple one I've used in the past. Also there is a free icon plugin for Paint.NET available here[^], which is currently my icon tool of choice. It does everything I need, and integrates really well into Paint.NET.

    Free Tools adobe

  • Is it possible to set another visual style only for my application [modified]
    R Rotted Frog

    No. You can't have application specific themes. If you need that sort of functionality, look at custom UI frameworks. The recent versions of MFC have skinned controls, which offer different visual styles (Office 2007, VS2008 etc.) Also third party MFC control vendors like BCGSoft or Codejock offer a lot of skinnable controls.

    C / C++ / MFC tutorial question

  • VC++ projects on Japanese OS not compile on English OS
    R Rotted Frog

    It shouldn't matter which OS you are compiling on. It is probably an issue with code pages. You may need to save the source file in UTF-8 format before you compile. If this still has problems, can you post a code sample and the errors so we can see what is happening.

    C / C++ / MFC c++ help question

  • Angry example
    R Rotted Frog

    Wasn't sure whether to post this in Clever code or here, but found this snippet in a link on VS standards compliance (http://msdn.microsoft.com/en-us/library/8yk3t00s%28v=vs.71%29.aspx[^]

    // defining_member_templates_outside_a_class.cpp
    // compile with: /LD
    template <class T>
    struct S
    {
    template<class U> void f(U);
    };

    template<class T> template <class U> void S<T>::f(U)
    { //defined out of line
    }

    It made me smile this morning. If you're thinking of complaining then just S<T>::f(U). :)

    The Weird and The Wonderful c++ visual-studio com tutorial

  • problem to draw line in list control
    R Rotted Frog

    You need to handle the custom draw notification and draw the whole item in the control, using GDI (or GDI+) API calls. For entries that are invalid, you can then draw a red line though then using MoveTo/LineTo. For an example of a ListView custom draw, read this article[^] EDIT: This article might be better that the C# one I originally posted... Using ListView control under Win32 API[^]

    C / C++ / MFC css help tutorial

  • How can find the text file encoded in other than ANSI format?
    R Rotted Frog

    It depends, For some file formats there is no way to tell them apart programatically (e.g. Chinese Big5 vs. Ansi). I imagine you are more interested in unicode specifically, though. For Unicode files there is normally a BOM (byte order mark) at the beginning of the file which tells you what the file format is. Look up Byte order marks on wikipedia for a really good explanation. Alternatively if you don't want to do this by hand, read this article[^] for a CStdiofile derived class that auto-detects the encoding.

    C / C++ / MFC question

  • How to get a value to return in a textbox
    R Rotted Frog

    More clarity about how the "change" happens in the figures would be helpful. For example: 1. Are you tring to update the figures whenever a new item is scanned?, If so you need to catch the scanning event (typically this would be an OnKeyDown or OnTextChanged event in a TextBox somewhere? 2. Are there lots of different places where the figures may change (e.g. the are lots of different people scanning in refurbs in different places) and you want to constantly check the database. If so a solution where you check the database at regular intervals might be better (e.g. use a Timer control and put the code in there). Without knowing exactly what you are trying to achieve and the thought process behind it, it's difficult to work out the best solution.

    C# database help question xml tutorial

  • FTW?
    R Rotted Frog

    Even more surprising is that it appeared convinced this was true even though the compiler gives an unreachable code warning and tell you that the check will always return true. But he probably didn't notice it hidden amongst the other 200 warnings. Sigh.

    The Weird and The Wonderful csharp ruby collaboration question

  • FTW?
    R Rotted Frog

    This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

    public bool SelectedByDefault
    {
      get { return \_defaultSelected; }
      set
      {
        // no, check isn't pointless, because serialisation can assign a null to a bool
        if (value != null)
        {
          \_defaultSelected = value;
        }
        else
        {
          \_defaultSelected = false;
        }
      }
    }
    
    The Weird and The Wonderful csharp ruby collaboration question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups