Skip to main content
edited to address complaints about the tone of the answer
Source Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

There are some issues with this function, some of them resulting from the fact that the task to be performed was poorly conceived to begin with.

  • The statement of the problem says that AsciiAscii takes a "one character string". You give it a character, not a one-character string.

  • The whole notion of the Note that the Ascii function Ascii is dumb. Acompletely unnecessary: a character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.

  • The statement of the problem says that the function returns a string. You do that, but boy, is that dumbdoes not make good sense. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers and Java programmers.

  • C# uses lowercase for formal parameters.

I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string.

  • The whole notion of the function Ascii is dumb. A character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.

  • The statement of the problem says that the function returns a string. You do that, but boy, is that dumb. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers and Java programmers.

  • C# uses lowercase for formal parameters.

There are some issues with this function, some of them resulting from the fact that the task to be performed was poorly conceived to begin with.

  • The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string. Note that the Ascii function is completely unnecessary: a character in the ASCII range is already a number representing its ASCII code.

  • The statement of the problem says that the function returns a string. You do that, but boy, that does not make good sense. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers and Java programmers.

  • C# uses lowercase for formal parameters.

I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

Remove redundant quote
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155

How can this be improved?

  • The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string.

  • The whole notion of the function Ascii is dumb. A character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.

  • The statement of the problem says that the function returns a string. You do that, but boy, is that dumb. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers and Java programmers.

  • C# uses lowercase for formal parameters.

How can this be improved?

  • The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string.

  • The whole notion of the function Ascii is dumb. A character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.

  • The statement of the problem says that the function returns a string. You do that, but boy, is that dumb. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers and Java programmers.

  • C# uses lowercase for formal parameters.

  • The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string.

  • The whole notion of the function Ascii is dumb. A character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.

  • The statement of the problem says that the function returns a string. You do that, but boy, is that dumb. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers and Java programmers.

  • C# uses lowercase for formal parameters.

This small part seems to be only a rant about c programmers
Source Link

How can this be improved?

  • The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string.

  • The whole notion of the function Ascii is dumb. A character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.

  • The statement of the problem says that the function returns a string. You do that, but boy, is that dumb. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers who are again trapped in the 1970s. Andand Java programmers.

  • C# uses lowercase for formal parameters.

How can this be improved?

  • The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string.

  • The whole notion of the function Ascii is dumb. A character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.

  • The statement of the problem says that the function returns a string. You do that, but boy, is that dumb. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers who are again trapped in the 1970s. And Java programmers.

  • C# uses lowercase for formal parameters.

How can this be improved?

  • The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string.

  • The whole notion of the function Ascii is dumb. A character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.

  • The statement of the problem says that the function returns a string. You do that, but boy, is that dumb. Why on earth would you return a number as a string when you could return it as a number???

  • It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.

  • "You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.

  • I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.

  • Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.

  • Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.

  • C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers and Java programmers.

  • C# uses lowercase for formal parameters.

Corrected "whomever" to "whoever" (both instances nominative case) and clarified the need for the same characters in different order to hash to different outputs.
Source Link
Loading
Source Link
Eric Lippert
  • 15k
  • 4
  • 39
  • 57
Loading