Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Victor
Jun 18, 2004

tef posted:

See, where you might use "result" I would use bln_flg_tst_cnd_args_x.
You almost made me spit coffee over my new, broken-in MS 4000 keyboard!

Adbot
ADBOT LOVES YOU

Victor
Jun 18, 2004
code:
string clientStr = this
    .publishToClients
    .OfType<PublishToSetting>()
    .Select(c => string.Format("{0}:{1}:{2}:{3}", c.Alias, c.Ip, c.Port, c.TheProtocol))
    .Join(",");
(string Join(string delimiter) is a method I made, because MS didn't include it by default, for some odd reason.)

Victor
Jun 18, 2004

_aaron posted:

Hahaha, that's pretty awesome. But correct me if I'm wrong here: most of that stuff is .Net 3.5 stuff, right? We are still using vs2005 (but will be upgrading soon), so that doesn't apply to our stuff. When we do make the switch, I will certainly keep this in mind.
Yup, .NET 3.5, C# 3.0.

Victor
Jun 18, 2004
Notice how the signature between what I posted differs from what you posted. Moreover, mine works on IEnumerable<string> and is an extension method. Here's the definition:
code:
public static string Join(this IEnumerable<string> strings, string delimiter)
{
    return strings.Any()
        ? string.Join(delimiter, strings as string[] ?? strings.ToArray())
        : "";
}

Victor
Jun 18, 2004
I'm all for a few intelligent conventions like what you've just posted (I'm not sure if the actual ones you posted are good or not). Consistency is really the important thing, within any given code base. And don't make it drastically different from other code bases you're going to be working on. Give the brain fewer differences so that the differences it does process are the relevant ones.

Victor
Jun 18, 2004
nebby, what if the programmers with whom you work just suck at giving proper context? Also, you repeatedly forget to note that this is much more important for dynamic languages, as things are less clear there. Have you looked into coding for the military, using ADA? It gets fairly close to your approach, but has compiler-enforced type safety. You can only get speed if you divide distance by time (or integrate acceleration by time, etc.).

Maybe I missed it, but I do not remember you ever explaining why your desire for Hungarian whatever is in the distinct minority of programmers. Does your approach really allow you to code more quickly and more accurately than other people, on average? (Take into account learning curve here!) To what extent are the problems you encounter, unique to your problem domain, or at least a very, very small fraction of programming?

The more I think about this, the more you must address the above if you want to stop digging/get out of the hole you've dug. Right now, you're some weird freak in most of our minds. I'm cutting you more slack than most, because I have very little respect for experience and track record, if I cannot understand the why behind the experience and track record. However, most people do, and you, my friend, have demonstrated zero.

Victor
Jun 18, 2004
I don't think we should stop at making programmers manage their own type systems in symbol names. I think they should have to code in assembly. Screw that: ones and zeros. Actually, what would happen if we made programmers code mechanically, maybe via some sort of punch card system that is about as reliable as the punch cards used in the Florida election? Surely, in that case, the bug count would go way down.

Victor
Jun 18, 2004

rotor posted:

We're gonna need bigger keyboards.
Apparently it's about as hard to go Hungarian (System Apps) as to learn a new keyboard layout, so this might not be a half bad idea!

Victor
Jun 18, 2004

yaoi prophet posted:

Is there a das keyboard version?
gently caress that, I want an OLED version.

Victor
Jun 18, 2004
Clearly, return is a function. :psyduck:

Victor
Jun 18, 2004

dustgun posted:

I should mention, just for the sake of mentioning, that this was written by a coworker of a friend of mine. I changed the method and variable names, but, it's real live code somewhere.
Are you a member of the NRA yet?

Victor
Jun 18, 2004
I dunno man, insert some underscores into the obfuscated version and it starts looking like Hungarian...

Victor
Jun 18, 2004
Clearly the input should be s and the output should be ret. :colbert:

Victor
Jun 18, 2004
I reserve r for Regex instances.

Victor
Jun 18, 2004

TRex EaterofCars posted:

Boo!

I use re for regex. It's far less common than returning a value, so it can get the extra letter.
Hrm, you might have just started to convert me from ret to r. Nobody tell nebby!

That Turkey Story posted:

he said that he was using the parenthesis not because he thought it was a function but because he wasn't sure of the order of operations.
Cool, I approve of this. It sounds like this guy does something extremely rare -- it seems like he actually tries to be aware of what he doesn't know!

quote:

(though honestly who really cares, some extra parenthesis never hurt anyone).
I'm one of those guys who doesn't want extraneous information screwing with my precious brain cycles.

Victor
Jun 18, 2004
I general, I'd keep away from stuff like s.IsNullOrEmpty(), but I think I would make an except for that specific case. Especially since the name itself acknowledges that null is a valid "argument".

Victor
Jun 18, 2004

floWenoL posted:

What happens when s is null?
The earth implodes.
code:
catch (NullReferenceException)
{
    Planets.Earth.FormBlackHole();
}

Victor
Jun 18, 2004
Gotta protect against FILE_NOT_FOUND!

Victor
Jun 18, 2004
You mean, a programming forum.

Victor
Jun 18, 2004
It's best to have boolean variable names that sound boolean, like hidden (or even isHidden). I prefix nonpublic class fields with _ -- it's simple and to the point. With respect to calling a method inside a class, I'm a bit conflicted: if there's no this., the method invoked has to be one belonging to the enclosing type, at least in C#.

Victor
Jun 18, 2004
I think this looks best:
code:
if( true == foo.equals(foo2) == true)
(Just don't do the same with false.)

Victor
Jun 18, 2004
We should just rename DISTINCT to FIX.

Victor
Jun 18, 2004

dwazegek posted:

If the key doesn't exist the dictionary will throw an exception, it won't return null.
Note if it is a NameValueCollection:

NameValueCollection.Item Property posted:

This property returns a null reference (Nothing in Visual Basic) in the following cases: 1) if the specified key is not found; and 2) if the specified key is found and its associated value is a null reference (Nothing in Visual Basic). This property does not distinguish between the two cases.
I learned something new: NameValueCollections allow .Add to be called multiple times with the same key, in which case a comma-delimited list is returned upon accessing that key.

Victor
Jun 18, 2004
Unless a throw was omitted from the catch{} statement above, then adding the catch{} changes the semantics to the exception being handled. Not good!

Victor
Jun 18, 2004

Bonus posted:

code:
  catch (Exception e)
  {
    transaction.Rollback();
    throw e;
  }
then any exception will be caught but the type of the exception propagated upwards will stay in tact. At least I think so, my Java is pretty rusty.
The above is horrible, as you lose the stack trace. Either throw;, or throw new DeleteFailedException(e); so that the stack trace is maintained via InnerException.

Victor
Jun 18, 2004

HappyHippo posted:

Hmm
code:
sometype GetInstance(string Reg)
{
      switch (Reg)
      {
            case "first_field":
                  return first_field;
            case "second_field":
                  return second_field;
            case "third_field":
                  return third_field;
            case "fourth_field":
                  return fourth_field;
            case "fifth_field":
                  return fifth_field;
             .
             .
             .
      }
}
For 11,000 lines. This is in C#. Ignoring problems with the program's structure, I was able to turn this into about 5 lines of code with reflection.
Wait, so you have a class with 5,500 fields?

Victor
Jun 18, 2004

BigRedDot posted:

Seriously, what is attempting to iterate past the end of a sequence, if not an exceptional circumstance?
This is standard operating procedure. In many, many different APIs, Read() will return 0 or null or some other sentinel value that there are no more values to consume. C++'s STL has iterators that evaluate to .end() when iteration is done -- .end() is not actually a valid element, it is one past the end of the sequence. The very nature of loops in [most] programming languages dictates that being able to get a last element that will never need to be processed (instead, it provides a sentinel value for a boolean "break out of this loop" test) is very useful. A fake, end-of-sequence element is occasionally added to facilitate this. No, exceptions are an ugly solution here, but may be the most elegant as stated above. I'm not sure whether static analysis makes this easier/possible, but the C# compiler implements iterators as state machines. No exceptions are required.

Victor fucked around with this message at 22:03 on Nov 8, 2008

Victor
Jun 18, 2004
The real WTF is in several online tutorials that teach you to use a StringBuilder for instances such as the above, instead of letting the compiler automatically combine all the string constants into one. It's pretty sad.

Victor
Jun 18, 2004
The real WTF is that Java doesn't provide single, simple methods to read/write all text/lines, like .NET does. Hmmmm, maybe just wanting to get a file's contents without caring about how is a common enough operation to provide a shortcut in the standard library?

P.S. Another problem with calling readLine in two places is that continue will screw you over.

Victor
Jun 18, 2004

tef posted:

What if b[] is being modified in a different thread?
[list=1][*]I'm pretty sure you get a new b -- I know .NET doesn't resize arrays in-place and I doubt Java does either.[*]Assuming in-place array modification, the code isn't threadsafe anyway.[/list]

Victor
Jun 18, 2004

ashgromnies posted:

who the gently caress in the history of computing thought, "ah, yes, xml is a decent markup language for organizing data... let's make code out of it"
When compared to some of the other utter and absolute crap out there, like healthcare's 837 file format, XML would be a godsend. One site calls it "overwhelmingly difficult to understand", and yet it's just supposed to be a hierarchical data format. Yes, there is much better for specific cases, but there is also much worse, and at least nubs can use XML...

Victor
Jun 18, 2004
Not to mention reentrancy issues...

Victor
Jun 18, 2004
For those of you with SQL2005, NEWSEQUENTIALID() was created for you:

MSDN posted:

Creates a GUID that is greater than any GUID previously generated by this function on a specified computer.

Victor
Jun 18, 2004
O(1) for very large values of 1.

Victor
Jun 18, 2004

Ledneh posted:

Spent the last hour reading this thread and now I'm extraordinarily worried I'm going to end up in here some day. There were so many in here that I didn't understand without explanatory posts :(
Anyone in here who claims to have never written code that could be submitted to this thread is a pretender*. The key is that you continue to learn and figure out ways to be less retarded.

* or hiiiilarious

Victor
Jun 18, 2004
Haha, there's more WTFage -- if the getter is called without a properly cased string, not only will the property fail to be set, but it won't complain, as it has no default: section. WTF indeed!

Victor
Jun 18, 2004
The WTF here is probably writing a logging framework instead of using one -- or did you really need to write your own?

Victor
Jun 18, 2004

twodot posted:

This is kind of bizarre in my opinion. With a sufficiently strong type system you can claim any information is part of the typing. There are trade offs involved with deciding what information you put into a typedef and what information you put into a variable name. Personally, I think it can be useful to put information like whether a variable counts characters or bytes into the variable name rather than as a comment in the variable declaration or as a named type. Jumping between usages and definitions has costs especially in more object oriented code where definitions are non-local.

Hungarian notation isn't anything more than a standardized method of encoding information about a variable into its name. This is something that is always done when a variable name is created, standardizing it isn't intrinsically bad. Though most people's usages of Hungarian notation is very bad.
I think this is the best way to frame the "pro-Hungarian" perspective that I've ever seen. I'd create a new thread, but I have little confidence that the discussion would stay at the level that has been maintained for a few posts here. I'm not saying that I agree with twodot, but one would be retarded not to acknowledge that the point brings up valid concerns.

Victor
Jun 18, 2004

Ryouga Inverse posted:

I challenge you to prove to me that mysql_real_escape_string() takes care of absolutely every possible SQL injection attack, including ones that may be discovered later.
This discussion fails because PHP and MySQL are so hosed up that if you are not paranoid enough, that if you don't pay absolute attention to security, you will lose and be hax0red. If you do "abc...'...wut".Replace("'", "''") in .NET, you are guaranteed that will work well. No encoding poo poo (everything is UTF-16 in .NET strings), nothing. There is no way you can fail unless you don't do that .Replace religiously. Now, few people are rigorous enough to do this, so they should suck it up and use parameterized queries. Whether you use prepared queries is immaterial -- that's only one way to parameterize in a safe way. I cannot believe there is so much loving bullshit on this issue. I can only attribute it to PHP and MySQL being lovely pieces of software. If you aren't anal about doing stuff right in the core layer, the layer upon which millions of people build, then you are worthless. You deserve to languish in the hell of bad code and ugly frameworks. I'm not sure I would work on PHP and MySQL if you paid me $1 million a year. They suck that much. The fact that plenty of people use these is irrelevant and you know it (or you are a retarded loser who never leaves his bubble).

I was just visiting this insults page and teapot's quote really resonated with me:

teapot posted:

No, it merely poisons minds, making programmers incapable of writing high-quality software and developing new ideas. It cripples their model of thinking by pushing them toward the optimal way of programming for severely mis-designed Microsoft products. Destruction of human minds' ability to improve is something that I don't take lightly.
I used to doubt this, but now I could not agree more. Except that Microsoft does not hold the patent on poo poo generation.

Victor fucked around with this message at 07:58 on Jan 8, 2009

Adbot
ADBOT LOVES YOU

Victor
Jun 18, 2004
I guess it's just hard for old people to be truly offensive other than, you know, being old and crufty and smelly with bad breath and only knowing ancient languages that stunt brand new minds. Since that's the kind of person who probably wrote up that site, well, you're not special enough to make it in.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply