Jeff H's Profile User Rating: -----

Reputation: 112 Stalwart
Group:
Active Members
Active Posts:
309 (0.24 per day)
Joined:
30-January 11
Profile Views:
3,218
Last Active:
User is offline Aug 17 2014 08:08 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Jeff H has not set their status

Posts I've Made

  1. In Topic: Method Complexity

    Posted 13 Aug 2014

    A little late but something not mentioned or to bring more attention to about TakeABreath example is its readability.


    Anyone person can only keep about 4 to 7 ideas or thoughts in their mind at one time.
    Breaking up methods into smaller parts that are not easily understood probably isn't any better.

    When you look at TakeABreath method it is easy to see that there 3 main parts inhale, process, exhale.
    There might be complex computations happening but, if all I need to know is call TakeABreath when a breath is needed that's it. If something changes and need to know what it does it is easily understood at a high level and do not require unnecessary information or noise to understand the lower level ideas.
    For example if need change the way oxygen is brought in I do not need to know about processing oxygen or exhaling to see to what happens when inhaling, or to put it another way it does not require having to understand, filter out, etc.. to see inhale implementation.


    Hopefully it makes sense but can you see how TakeABreath and its functions is close or organized to the way people naturally read or organize an idea? You appreciate code like that when scrolling up constantly because a method has 34 different local variables and it is 5th time you had to look because you can't remember what this one variable type is and that leads to some other class that constructor is just as bad.

    It has to happen somewhere but making code readable and broken up in way that makes it easy read is a very helpful skill.


    Not sure what your doing but might lend itself to CQS design.
    Not CQRS and the terminology has nothing to do with relational database.

    Quick overview is every method is a query or command.
    A query has NO side effects and returns a value. This could be value in private field etc..
    A command returns void and performs an action or changes state.

    A command can call a query but a query can not call a command.


    Also you can use functional programming concept of a "maybe" or in F# a maybe.
    Basically a collection constrained to having either 0 or 1 items instead of settings variables to null and null checks
  2. In Topic: need to count vowels in a string

    Posted 18 Sep 2013

    Not meant to be a correct a solution but no matter the problem always good to think of different approaches to see if better, validate another approach, look at problem differently, etc....

        class Program
        {
    
            static bool[] chars = new bool[126];
            static char[] vowels = new char[] { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
    
            static Program()
            {
                foreach (var v in vowels)
                {
                    chars[(int)v] = true;
                }
            }
            static void Main(string[] args)
            {
    
                Console.WriteLine("Enter a string");
                string test = Console.ReadLine();
    
                PrintValue(test);
    
                Console.Read();
            }
    
            private static void PrintValue(string test)
            {
                int count = 0;
                foreach (var c in test)
                {
                    if (chars[(int)c])
                    {
                        Console.Write(c);
                        count++;
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
                Console.WriteLine("Total = {0}", count);
            }
        }
    
    

    Not sure how but what counting 'Y'?
  3. In Topic: What the Duck - ForEach, IEnumerable, IEnumerator DuckTyping

    Posted 18 Jun 2013

    Thanks,

    Probably need to add that to Kindle collection, I just noticed in some MSIL that it did not call the methods through the interface.
  4. In Topic: Random not so random?

    Posted 13 Jun 2013

    View Post_HAWK_, on 13 June 2013 - 10:19 AM, said:

    The purpose I had for this to create what I thought would be a better Binding name for some dynamically loaded DataColumns into a Silverlight DataGrid for importing a csv where the number of columns could be any value. One could have just used a CharArray from which the iteration variable could be used to get the char in that array, but this has limits and not totally dynamic and able to complete it's job no matter what was handed to it. This way I can have the function assign the binding name(also the column name) which is a valid binding name as well. Many thanks for the info.


    Sorry if I am way off here and not understanding the problem as I have never messed with Silverlight, but if I am understanding correctly you are just needing unique names. The first thing that comes to mind is to keep static counters and increment them each time a name is needed.

    Can they be named
    A0
    A1
    ....
    A2147483647
    B0
    ...

    If so,

    Sorry I use C# but here is a little example of the idea and just slapped it together and I spent the 95% of time trying to assign the Char with 'A' instead of "A".

    No logic for testing when character reaches Z
    Module Module1
    
        Sub Main()
    
            For i As Integer = 1 To 10
                Console.WriteLine(UniqueName.GetName())
            Next
    
            For i As Integer = 1 To 100
                Console.WriteLine(UniqueName.GetName())
            Next
    
    
            For i As Integer = 1 To 1000000
                Console.WriteLine(UniqueName.GetName())
            Next
    
            Console.ReadLine()
        End Sub
    
    End Module
    
    Public Class UniqueName
        Private Shared character As Char = "A"
        Private Shared counter As Integer = -1
    
        Public Shared Function GetName() As String
            If Not counter < Integer.MaxValue Then
                character = Chr(Asc(character) + 1)
                counter = -1
            End If
    
            counter = counter + 1
            Return character + counter.ToString()
        End Function
    
    End Class
    
    



    If you went from A to Z it would give you 2147483621 unique names, and if that is not enough you could add logic to add characters when it reaches Z
    ....
    Z2147483647
    AA0
    ....
    AZ2147483647
    BA0

    Sorry if I misunderstood and not familiar with VB and if shared variables have any "gotchas", etc....
  5. In Topic: Adding a "+" between integers

    Posted 5 Jun 2013

    Have a look at the String.Join method which does exactly what you want. If you look at its implementation it uses StringBuilder so not waste resources creating a new string for each concatenation. In your example the small amount would not make a difference, but with a larger set would help in performance.
    Also if you know the start and ending number there is Enumerable.Range

    Putting aside parsing the start and ending number and appending " = total" to the end you can build the string with 2 methods above easily.

    Module Module1
    
        Sub Main()
            Dim nums As IEnumerable(Of Integer) = Enumerable.Range(1, 10)
            Dim addtionString As String = String.Join("+", nums.Select(Function(i) i.ToString))
            Console.WriteLine(addtionString)
            Console.Read()
    
        End Sub
    
    End Module
    
    

My Information

Member Title:
D.I.C Regular
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Comments

Page 1 of 1
  1. Photo

    rossypz Icon

    15 Aug 2014 - 01:43
    Hi,I Am Mrs Rose.I am writing to know you more for i have an important issue to discuss with you. for more details write me on This Email: rosse4u2006@hotmail.com wrte to my email..
    God bless.
    Roseline
  2. Photo

    Jeff H Icon

    14 Jul 2011 - 04:21
    To show it twice
  3. Photo

    Jeff H Icon

    14 Jul 2011 - 04:21
    To show it twice
  4. Photo

    Jeff H Icon

    13 Jul 2011 - 17:41
    Everything I do in my profile it does it twice.
  5. Photo

    Jeff H Icon

    13 Jul 2011 - 17:41
    Everything I do in my profile it does it twice.
  6. Photo

    raziel_ Icon

    13 Jul 2011 - 16:16
    lol i just saw your having fixo added twice in your friend list :D
  7. Photo

    Jeff H Icon

    09 Jul 2011 - 08:52
    Thanks smohd,
    and nice work yourself
  8. Photo

    smohd Icon

    03 Jul 2011 - 16:21
    Hi, nice work in VB.NET forum. keep it going :)
Page 1 of 1