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
FrantzX
Jan 28, 2007

nebby posted:

Yeah. One thing I think I've come to conclude is that one small thing that would go a long way towards a middle ground between my (supposedly crazy) viewpoints and the "gently caress it do whatever you want and use 'common sense'" viewpoint is a convention to use noun-adjective instead of adjective-noun in variable names and return type-verb in method names (or, at the very least, be consistent.)

I've been digging into some 3rd party code and sometimes it's the "RunningActivity" and other times it's the "ActivityToRun". Sometimes it's "RedColor" and sometimes it's "ColorRed". Is "CountApples" a function pointer to something that counts apples and returns nothing, or a variable containing a number of apples/a function that gets the count of apples?

I suppose the variable/function type would give some information. But not all of program in a strongly-typed language like C# or Java.

Adbot
ADBOT LOVES YOU

FrantzX
Jan 28, 2007
code:
public String GetProperty(String key)
{
     ValueType value;
     if(map.TryGetValue(key, out value) == true) return value.ToString();

     return null;
}
I'd do it this way for only one lookup plus it won't throw an exception is the key is not found in the dictionary.

FrantzX
Jan 28, 2007

qntm posted:

http://en.wikipedia.org/wiki/Python_%28programming_language%29

While many programming languages round the result of integer division towards zero, Python always rounds it down towards minus infinity; so that 7//3 is 2, but (−7)//3 is −3.

Python provides a round function for rounding floats to integers. Version 2.6.1 and lower use round-away-from-zero: round(0.5) is 1.0, round(-0.5) is -1.0. Version 3.0 and higher use round-to-even: round(1.5) is 2.0, round(2.5) is 2.0.

??!

http://en.wikipedia.org/wiki/Rounding#Round_half_to_even

FrantzX
Jan 28, 2007
Does it count as a horror to post a picture of HTML?

FrantzX
Jan 28, 2007
My first thought was some sort of COM MTA/STA threading issue, but still, why would you sleep the current thread instead of joining the created one?

FrantzX
Jan 28, 2007

Flobbster posted:

The best kind of error handling is when you detect enough context to know exactly what the user wanted to do, but you still just don't do it.

Command line processing can be enough of a pain in the rear end. Why add context guessing heuristics to the mix? I can only see that ending in madness.

FrantzX
Jan 28, 2007
As a C# programmer who is learning Java for Android development, I am curious. What are Java's strengths?

FrantzX
Jan 28, 2007
C# code:
public struct Indexed<T>
{
	public Indexed(Int32 index, T item)
	{
		Index = index;
		Item = item;
	}

	public readonly Int32 Index;

	public readonly T Item;
}

public static class Extensions
{
	static IEnumerable<Indexed<T>> Indexed<T>(this IEnumerable<T> sequence, Int32 startindex = 0)
	{
		Int32 index = startindex;
		foreach (T obj in sequence) yield return new Indexed<T>(index++, obj);
	}
}
LINQ & extensions method are some the best features I have ever seen in a language.

FrantzX
Jan 28, 2007
I dunno, seems roughly equivalent to me. It's either a hardcoded path string to a config file with file IO to read/parse information, or a hardcoded connection string to a database with SQL to read/parse information. Either way, things can go wrong at runtime.

FrantzX
Jan 28, 2007
Isn't everything in the System.Drawing namespace just a thin wrapper over the GDI API?

FrantzX
Jan 28, 2007
This entire conversation about nested iteration in Python is proof that LINQ is the best thing ever.

FrantzX
Jan 28, 2007

Newf posted:

It's definitely possible but I can't think of any reasonable scenario where it'd be the case.

An I/O request with a decent chance of failure. Web, serial port, etc.

FrantzX
Jan 28, 2007

Kazinsal posted:

A lot of Windows' API has been unchanged for a distressing number of years. I mean, take a look at the Hello World example from the Windows SDK circa 1985 and tell me how many functions you recognize...

http://www.charlespetzold.com/blog/2014/12/The-Infamous-Windows-Hello-World-Program.html

You know, there's a 50/50 chance that you can compile and run that exact code.

FrantzX
Jan 28, 2007

xtal posted:

Commas are whitespace so commas and spaces are redundant. A map in Clojure is {key value key value}.

Since when are commas whitespace?

FrantzX
Jan 28, 2007
There is no idea so bad that no one hasn't implemented it.

FrantzX
Jan 28, 2007

zergstain posted:

I asked since it looked like RandomBlue was complaining about inconsistent behaviour with path separators. At any rate, I can see the rationale for why Path.Combine() works that way.

I don't really do .NET, but it looks like this answer I found on SO would work for making sure given two paths, that one is a subdirectory of the other. Or just reject any absolute paths or paths with '.' or '..'

What about paths with ".." in the middle, for example: c:\Windows\System32\..\..\Windows\..\ProgramData
Try typing that into Explorer. It works.

FrantzX
Jan 28, 2007
Python code:
def _ReadLong(fs, endian = _DEFAULT_ENDIAN):
    return struct.unpack(endian + 'l', fs.read(4))[0]

def _ReadLong64(fs, endian = _DEFAULT_ENDIAN):
    return struct.unpack(endian + 'q', fs.read(8))[0]
Why would you choose these function names?

FrantzX
Jan 28, 2007
That seems OK to me as well. If iteration order is not defined or guaranteed, then randomizing the order is perfectly acceptable. I suppose randomization does have a performance cost, but would it matter on a practical level?

FrantzX
Jan 28, 2007
code:
if (key == 0)
{
    parsestate.ReadOperand(typeof(UInt16));
}
if (key == 1)
{
    parsestate.ReadOperands(typeof(Int32), typeof(Int32), typeof(Int32));
}
else
{
    parsestate.ReadOperands(typeof(UInt16), typeof(Int32), typeof(Byte));
}
I hate myself sometimes.

FrantzX
Jan 28, 2007

JawnV6 posted:

I worked with a contractor that didn’t escape strings. When the device was booting, it would print some garbage that included a bell character. My terminal would dutifully ding every clean boot.

By the time I sorted it out I was trained to the bell, if init was messed up it wouldn’t ding, so I left it in like a Pavlovian dog.

What's worse, using a bell character, even by accident, or the fact that it still works?

FrantzX
Jan 28, 2007
code:
 void FillFirstAddressRQ(byte[] array) {
        array[0] = -16;
        array[1] = 65;
        array[2] = 16;
        array[3] = 0;
        array[5] = (array[4] = 0);
        array[6] = 57;
        array[7] = 17;
    }
Shouldn't that be
code:
array[5] = (array[4] == 0);
?

FrantzX
Jan 28, 2007
Considering that all the other casts are using types with explicit sizes, my first question would be, what is result of sizeof(int)?

FrantzX
Jan 28, 2007
Shouldn't the default implementation of GetHashCode() or equivalent just return 0? You should either explicitly define a hashing method or not get one at all.

FrantzX
Jan 28, 2007
Visual Studio is mother, Visual Studio is father.
I'm likely the only one who will get this reference.

FrantzX
Jan 28, 2007
I am starting to be of the belief that the assumption that char (a code unit of some encoding) == byte (an unsigned 8-bit integer value) is one of the two biggest mistakes ever made in the design of programming languages.

The other is that sizeof(int) is platform dependent.

FrantzX
Jan 28, 2007
I can see why a platform dependent integer type is needed, pointers for example. However, it shouldn't be the default int type. Going thru APIs like win32 or opengl shows how much effort people go thru nailing down int sizes.

If I had a time machine, this is how integers should work in C and derivatives:

byte / sbyte (maybe with a alias of int8 / sint8 for consistency)
int16 / uint16
int32 / uint32
int64 / uint64
word / sword - a platform dependent integer type that is the native word size for the running system.

Also:

quote:

target-determined type that can express any number of objects that you can have simultaneously in your program.
Isn't this size_t?

Adbot
ADBOT LOVES YOU

FrantzX
Jan 28, 2007
What is the definition of a 'library I/O function'? I assume that this is more specific than just any function (does in-lining matter?)

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