Jump to content

  • Log In with Google      Sign In   
  • Create Account


boogyman19946

Member Since 15 May 2010
Offline Last Active Jul 24 2014 07:06 PM
-----

Posts I've Made

In Topic: Costs of (Re)Designing a Programming Language

20 April 2014 - 09:49 AM

That's what I imagined would be the case. I'm actually looking for this information for a report for a class. Basically, I'm writing a report from the point of view of an organization having accomplished a proposed project and I'd like to outline some of the costs. I imagine that if I can't find the exact number, I'll be allowed to just eyeball it because after all the assignment is more focused on actual structure of the report rather than absolute correctness of the data (but the numbers ought not to be that far off biggrin.png).

The exact change being made is simply adding some functions to an interface so that the old interface doesn't actually change, but new functions are added to make the new interface consistent with the existing ones.

I had a feeling that a small change like that wouldn't really cost all that much and I wasn't sure how much information I would have been able to find on the exact cost precisely because Oracle is the owner of the language and they have complete control over it. I'll probably end up digging around their site later to see if I can come up with anything.


In Topic: Better way to write this code

19 February 2014 - 10:22 PM

The second return statement is necessary because the compiler can't just assume the first return statement will execute. There is no guarantee that a node in the list matches the argument key.

 

Therefore, the return statement in question should return a value that one would expect if there was no entry matching the given key. If you can't return null, you could write it like this:

public Coordinates GetNodeCoordinates(int number)
        { 
            foreach(Node node in nodes)
            {
                if (node.Number == number)
                {
                    return node.Coordinates;
                }
            }
            return new Coordinates(); 
        }

But you won't be able to tell if you actually found a valid set of Coordinates unless you save that state somewhere. The above code is pretty much the same as yourself, with the exception that it only creates a new Coordinates at the last minute and only when needed. Not a great improvement, but some start.

 

I don't know C# very well. I thought it would have a reference system more similar to Java, but in Java you can return a null value for just about anything that's not a primitive.


In Topic: Trouble with strings and chars with arrays and loops

14 February 2014 - 10:04 PM

Yeah that is ok (not very efficient though, if the input is all zzzzzzzzzzzzzzzzzzzz) if you can guarantee that the input only has letters in the alphabet, otherwise, use the HashMap variant.

 

Of course, HashMap is the most reasonable choice as solution. I just have a special place in my heart for table methods ever since I discovered them :D


In Topic: Trouble with strings and chars with arrays and loops

14 February 2014 - 08:41 PM

I myself would prefer to use a simple table method although it really depends I guess. A HashMap will do the job and will probably be more straightforward (I guess it depends on what you're more used to), but if you are bound to using arrays, the following solution is probably what I'd use:

final char alphabet[] = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // A little ugly over here, but, that's meh.

String str = "Some string text goes here";
char charArr[] = str.toLowerCase().toCharArray();

int charCounters[] = new int[alphabet.length];
for(char character: charArr) {
   for(int i = 0; i < alphabet.length; i++) {
      if(character == alphabet[i]) {
         charCounters[i]++;
         break;
      }
   }
}

In Topic: Trouble with strings and chars with arrays and loops

14 February 2014 - 08:24 PM

charAt( int ) returns the primitive char, so you can't call functions on it. The mistake is obvious: you need to use == instead of =. Single equal sign assigns to variables (which is why your compiler is complaining about needing a variable), and double equal signs compare equality (which is what the if-statement is expecting).


PARTNERS