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
leterip
Aug 25, 2004

seiken posted:

Woah, why have I never thought of the !! operator before? Since it doesn't do anything you can pepper it around your code to indicate the important bits!

Why stop at !! when you can prefix the really important bits with !!!!!!!!!!!!

Adbot
ADBOT LOVES YOU

leterip
Aug 25, 2004
Golang has a gofmt command that automatically reformats code so you can just run it in a pre-commit hook and never even think about it ever again.

leterip
Aug 25, 2004

The Gripper posted:

Why is this?

Python Reference posted:

Formally, if a, b, c, ..., y, z are expressions and op1, op2, ..., opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once.

So (2 > 1 is True) evaluates to (2 > 1 and 1 is True) which is False. The parenthesis stop the expansion. (This one took me a while to figure out.)

leterip
Aug 25, 2004
Whenever I see ~/fn~ I think


It's so unique :allears:

leterip
Aug 25, 2004
I like to think of php variables as one big name mangling (for local variables!) hash map and $ is the accessor method. I'm not sure if that makes it more or less of a horror. At this point the value could overflow at any time anyway.

leterip
Aug 25, 2004

pseudorandom name posted:

The could've made format strings use "yyyy", "mm", "dd" etc. instead, which would be both easy to remember and easy to read.

Why is using a bunch of different character codes that necessarily will have overlap (minutes vs months, the number of different ways of shortening a day/month) easier to read than reading a date in the format you want it to look like?

I don't see why its such a terrible idea. It feels like the backlash against it is just because it's different.

leterip
Aug 25, 2004

The Gripper posted:

If you look at code with a datetime format string from any other language you immediately know "hey, that's the format of a datetime".

With this, it looks like the date and time are significant rather than the format of the date and time, it's confusing to anyone new to Go and to anyone just skimming code it's easy to get mixed up. Consider: http://play.golang.org/p/Vkbx2djlF5

I wouldn't hesitate to say most people would expect t.Format("2006-01-02") to be doing something with the date 2006-01-02, not creating a datetime format string from it.

So your argument is that because it's different people might be confused by it? There's only one way to format dates in Go with the standard library, so if you're familiar with Go that's a non-issue. Imagine if Go was the standard way and they came out with strftime. You could make the same argument the other direction.

leterip
Aug 25, 2004

The Gripper posted:

My argument is that using an actual date/time as a format string is confusing, because everywhere else (and I mean everywhere, not just in Go) a written date or time means "this date or time" not "any date that fits this format". Using HH:nn:ss also has the benefit of differentiating a format string from a date or time; in Go the meaning of "12:34:56 2006-01-01" different (literal datetime or datetime format string) depending on where it is used.
"12:34:56 2006-01-01" doesn't have a different meaning. That is just a string that specifies a date. It isn't a valid formatting string, and that was easy to see by inspection.

To not be pedantic, the only time the context changes is when it is used in a specific method of a specific type. It's not like format strings are littered throughout code confusing people as to if they are specifying a date or not. There are literally two functions that accept a layout and in both cases it is clear from the local context that it is a format string, if not just by the calling method, but by the fact that it is specifying a specific date/time that if you are familiar with Go is clearly a format time.

The Gripper posted:

Edit; it's a novel idea and simplifies creating format strings, but in practice it is confusing (hang around in the #go-nuts irc channel and see how often people come in confused about this exact thing).
But how many of those questions are because someone confused the format string with a date string in the code, as you suggest is the problem? From looking at my logs, it seems most were confused by the system because it was new to them. I don't think a single person has mixed up the meaning in the way you describe.

The Gripper posted:

Also I wasn't arguing that it's confusing because it's different to strftime, just that when I see a date I expect the interesting part to be the date, not the formatting of it's elements.
(and since it wasn't mentioned, the format strings can't be just any date/time, they have to be a datetime constructed from it's formatting rules e.g. rather than remembering that %H is hour in 24-hour time, you have to remember "15" has that meaning. I can't find a page that actually lists the meaning of each set of digits, but off the top of my head 15 = 24hr hour, 04=minutes, 03=seconds, 2006=year, 01=month, 02=day. This instead of %H, %M, %s, %y, where mistakes are immediately obvious).

It's really just a bad, confusing system.
Indeed, it is just another way to write a formatting system, except instead of having to remember what %H means because some programmer decided it, you can derive what the 24-hour time format code is by remembering what date they used, which was chosen to be trivial to remember. It is just a very simple and logical method of creating a timestamp format specification. Isn't that amazing that you could define what those were off the top of your head with minimal exposure?

leterip
Aug 25, 2004

The Gripper posted:

I honestly couldn't tell you which digits represent minutes and seconds, and the same with which digits represent days and which represent months. I could have them backwards, I just guessed at their order. Compared to strftime where mixing up %M and %s is obvious, mixing up 03 and 04 in go is not.
%m vs %M

The Gripper posted:

There have been numerous that have mistaken the use of Format() and related methods, maybe not mistaking the format string with date in the code, but definitely mistaking the required parameter as being "a date" rather than "a format string".

So because they were unfamiliar with this different system they had an issue with how the format was specified. Once they learned about how the system worked, there were no more problems. There could be an argument for better documentation on the methods that take a layout, but that's not a problem with the system.

The Gripper posted:

Honestly it tries to solve a problem ("time format strings are confusing") and instead makes a carbon copy of the problem with more confusing element names (digits instead of %X). It's a net negative for the developer (you still need to know the substitutions as you would with strftime, however they no longer have a letter attached that gives it meaning) and there's marginal benefit to an observer (you can see what the result will look like immediately).

I prefer strftime formats over Go's implementation because it is better, not because I'm opposed to positive change.
Code is read a lot more than it is written. Being able to see exactly what the output format will look like is a huge win. You're right you still have to know how to format strings. There is no formatting specification that would remove that need. The point in that instead of having to memorize how strftime works or go look it up, you can just derive it because it is totally logical with no arbitrary decisions in what letters or capitalization means what. There are actual technical problems with this format (you cant easily get the week number, or the numeric day of the week, cross language specifications, but strftime loses it's ease of remembering there), but I don't think it being confusing is one of them.

leterip
Aug 25, 2004

Golbez posted:

PHP, is_readable(), has a curiosity in its documentation.

OK? So you run it on a filename and it tells you if it both exists, and is in a readable permission. Awesome.

Except...

I just tested it on a nonexistent file and it return false and did not throw a warning. So what on earth does 'upon failure' mean? What situation could a built-in function like this fail that doesn't count as a fatal error?

The bigger horror is that it exists at all. There is no way to provide that function without creating a race condition. What if someone deletes the file in between that call and your attempt to read it?

leterip
Aug 25, 2004

Golbez posted:

And if I try to run fopen() on a non-existent file, it throws a warning. Keep in mind that it also returns false. The documentation even helpfully suggests using @ to suppress the warning. Perhaps PHP functions should throw exceptions, because this seems like a reasonable place for that.

The point is that you have to assume that the fopen() call could raise a warning regardless of how much checking you do because by the time you get to actually opening the file the state of the filesystem could be different, so why bother doing the checking? It's a completely worthless function.

leterip
Aug 25, 2004

bobthecheese posted:

code:
$ for i in $(seq 12 -1 1) ; do date -d "today -$i months" ; done
Mon Oct 31 22:59:31 EST 2011
Thu Dec  1 22:59:31 EST 2011
Sat Dec 31 22:59:31 EST 2011
Tue Jan 31 22:59:31 EST 2012
Fri Mar  2 22:59:31 EST 2012
Sat Mar 31 22:59:31 EST 2012
Tue May  1 22:59:31 EST 2012
Thu May 31 22:59:31 EST 2012
Sun Jul  1 22:59:31 EST 2012
Tue Jul 31 22:59:31 EST 2012
Fri Aug 31 22:59:31 EST 2012
Mon Oct  1 22:59:31 EST 2012
What a strange year this has been...

How would you define March 31st - 1 month? Feb 31st and normalizing seems reasonable to me.

leterip
Aug 25, 2004

Zombywuf posted:

BRB posting "sort a list" exploits to Stack Overflow.

It doesn't consider anything posted after the xkcd comic.

Adbot
ADBOT LOVES YOU

leterip
Aug 25, 2004
Medical records and gibberish? Gotta be MUMPS.

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