|
Manslaughter posted:The API service I'm trying to communicate with is sending me ampersands inside of its xml. And not &, just plain old & by itself. I don't think I've ever run across one that didn't do this yay for sanitizing XML before you can actually use it.
|
# ? Dec 20, 2013 01:16 |
|
|
# ? May 30, 2024 13:09 |
|
PleasingFungus posted:if (bool_value == true) ... is longer code, to no benefit & reduced readability. Quite the opposite, in readability terms. If you're skimming code, and your native language is English, you read it as "if bool_value is true" and are able to separate out the semantics of type, even if you missed the variable declaration. The compiler doesn't care either way. Anybody who has to work on your codebase might. If you're using it with any variable that isn't bool (or doesn't have a clean conversion), then that is more of a problem than being explicit in your comparison. E: vvvv That too. vvvv One Eye Open fucked around with this message at 02:17 on Dec 20, 2013 |
# ? Dec 20, 2013 01:59 |
|
One Eye Open posted:Quite the opposite, in readability terms. If you're skimming code, and your native language is English, you read it as "if bool_value is true" and are able to separate out the semantics of type, even if you missed the variable declaration. The compiler doesn't care either way. Anybody who has to work on your codebase might. In readability terms you should use a variable that makes it read properly. if (shouldContinue && (hasConnection || canLog)) {...}
|
# ? Dec 20, 2013 02:04 |
|
Gazpacho posted:If you've successfully replaced a 45,000 line system with 1200(!) unit-tested lines — actually done it, not talked about it and underdelivered — chances are you're already so far ahead in the best practices game that there's not much to tell you. The codebase I inherited was created by a mechanical engineer, handed to another mech, then to some dipshit who didn't know what he was doing, and then two CoEs before I got to it. Nobody ever had time to refactor or rewrite or do anything of the sort, so the entire thing was basically a ball of duct tape a rubber bands held together with paper clips and bandaids and powered by the souls of sacrificed orphans. One of the first things I found when I got this job, like in my first month, was a chunk of 1000+ lines of code repeated four times in separate pieces of the code, which handily explained why none of my bugfixes were working. poo poo like that is what I had to deal with. Also that discussion about making everything into a class from a couple pages back. The project is test automation software, like Jenkins but way cooler, so it handles basically two things, installing software and running software. The stuff I inherited would model a software plugin as a class and like code:
because gently caress you, why would you make that a class? Replacing a few dozen xml files with a MySQL database really helped as well. For what it's worth (not much, I know), Visual Studio code metrics of old software (top) vs new software (bottom) theres a couple projects of a few thousand lines each that can't have metrics calculated in the old poo poo for whatever reason, and looking at this now is telling me that I need to do some refactoring myself, whoops. I'm sure if I went back to the old code and poked around I'd find tons of stuff that'd fit into this thread quite nicely e: and while I'm on the subject, I have never found an article that succinctly explained how the gently caress VS calculates that maintainability index or what it even loving means. I'm pretty sure it doesn't actually mean anything but what do I know Sockser fucked around with this message at 02:59 on Dec 20, 2013 |
# ? Dec 20, 2013 02:55 |
|
http://blogs.msdn.com/b/codeanalysis/archive/2007/11/20/maintainability-index-range-and-meaning.aspx
|
# ? Dec 20, 2013 03:35 |
|
Volmarias posted:Since you wrote it, and you're running it, have you considered fixing it? It's an idea, of course I had no idea how much of a pain in the rear end reconstituting the unsent email and did not want to interrupt it. I had to step out of the office for a while and when I got back there was an email stating there was a typo in the email we're sending out and to fix the typo before continuing. I managed to cancel the emailer, fix the typo and create a new SPROC to list all the unsent emails from the group we are sending and repopulate with that, and fire it up again. In my haste I forgot to take another five minutes to remove the MessageBox and recompile this thing. One of the improvements for the emailer program is the ability to create emails to send and replacing the simple text box for the email body with a rich text box to show formatting. I showed a demo of the program for the other programmers Monday with the implicit understanding that there were things that needed to be fixed and no testing done on it. I did not expect my boss to tell me today that we are using this for real. I have a feeling this happens a lot in the programmer community. Things like this make me glad I'm on alternate work week because three day weekends rock.
|
# ? Dec 20, 2013 03:56 |
|
Dren posted:A list of examples of operators behaving in incongruous ways depending on their arguments is php-like. How is that funky? That's been a common convention for boolean operators (in languages that permit them to operate on non-booleans at all) since Lisp.
|
# ? Dec 20, 2013 05:40 |
|
It also makes a bit of sense when you consider the short-circuiting nature of boolean operators. False and f() won't evaluate f(). You need to think of the and / or operators as combinators that return either the left-hand or right-hand expression, rather than something that returns the result of the purely logical AND / OR. Is this a good thing? Not sure. It's obviously a lot easier to implement and more performant in a lower-level language, and it allows for some language tricks like fire(employee_name or "shrughes") for when you need a default value.
|
# ? Dec 20, 2013 05:48 |
|
Suspicious Dish posted:The same thing is true in C as well. (C99, 6.5.13p3) "The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it yields 0." You are programming by superstition.
|
# ? Dec 20, 2013 08:27 |
|
Scaevolus posted:People get all emotional when you start calling their language "weak", and smug when their language is "dynamic".
|
# ? Dec 20, 2013 09:03 |
|
Suspicious Dish posted:Is this a good thing? Not sure. It's obviously a lot easier to implement and more performant in a lower-level language, and it allows for some language tricks like fire(employee_name or "shrughes") for when you need a default value. It also allows for people not to explain those tricks, which causes everyone who learns Python first to try code:
|
# ? Dec 20, 2013 09:47 |
|
Dren posted:A list of examples of operators behaving in incongruous ways depending on their arguments is php-like. That's because you don't actually understand what 'and' does: Python.org posted:x and y: if x is false, then x, else y (2)
|
# ? Dec 20, 2013 09:55 |
In languages that lack an explicit expression-if construction, having "and" and "or" return its arguments is a massive help. For instance in Lua, foo and bar or baz, equivalent to C ternary foo?bar:baz. The same also works in Python, and I prefer it to the bar if foo else baz construct, only because it keeps the condition first instead of stuffing it in between the two values.
|
|
# ? Dec 20, 2013 10:02 |
|
nielsm posted:In languages that lack an explicit expression-if construction, having "and" and "or" return its arguments is a massive help. For instance in Lua, foo and bar or baz, equivalent to C ternary foo?bar:baz. The same also works in Python, and I prefer it to the bar if foo else baz construct, only because it keeps the condition first instead of stuffing it in between the two values. I don't like it, because it looks like it's equivalent to foo?bar:baz but isn't.
|
# ? Dec 20, 2013 10:43 |
|
seiken posted:(C99, 6.5.13p3) "The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it yields 0." It appears I am, yep. The program I was debugging before that did the equivalent(a && b) * 100 was in JavaScript, where the convention works. I thought it picked it up from C, but I guess not.
|
# ? Dec 20, 2013 10:55 |
|
Using booleans as integers also has value when working with architectures that are not boring. For example, consider vector machines - they can execute instructions that operate across an array of values, but each element of the array must be processed the same. In essense, this is a very simple 'map' operation. Consider an expression like this: code:
code:
Interestingly, this is pretty much how GPUs work (in that both branches of a conditional are always taken), although you don't have to perform the above decomposition yourself.
|
# ? Dec 20, 2013 11:29 |
|
Amarkov posted:It also allows for people not to explain those tricks, which causes everyone who learns Python first to try this would work in Icon
|
# ? Dec 20, 2013 12:39 |
|
nielsm posted:In languages that lack an explicit expression-if construction, having "and" and "or" return its arguments is a massive help. For instance in Lua, foo and bar or baz, equivalent to C ternary foo?bar:baz.
|
# ? Dec 20, 2013 13:16 |
|
QuarkJets posted:That's because you don't actually understand what 'and' does: I understand. And I know about Python's ghetto ternary operator. The sticking point for me was that the examples listed show what appears to be incongruous behavior, though I suppose they're really about both the behavior of and as well as the overloaded behavior of *: code:
seiken posted:(C99, 6.5.13p3) "The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it yields 0." python.org posted:x and y: if x is false, then x, else y (2) I find the idea that boolean operators should return 1 or 0 more intuitive but it seems like people from functional programming backgrounds prefer the other way since I think I've seen some arguments here about the utility of boolean operators returning the truthy argument in functional languages.
|
# ? Dec 20, 2013 14:53 |
|
Athas posted:
Not quite, most modern GPUs have MIMD branching, but for if..then..else blocks, every path conditional is evaluated. (Here it's explained for GPGPU stuff)
|
# ? Dec 20, 2013 16:16 |
|
So we've got this database with millions of records that is constantly read and written to. There's a nightly job that pulls in data from an external source that's encoded as UTF-8. Our database is configured with a UTF-8 charset:code:
code:
|
# ? Dec 20, 2013 16:18 |
|
How anything can default to ANSI code pages in this day and age is beyond me.
|
# ? Dec 20, 2013 17:39 |
|
Ender.uNF posted:How anything can default to ANSI code pages in this day and age is beyond me. Also neat: this is mysql (huzzah), so latin1 is an extend ISO-8559-1 charset used by Microsoft called cp1252. quote:latin1 is the default character set. MySQL's latin1 is the same as the Windows cp1252 character set. This means it is the same as the official ISO 8859-1 or IANA (Internet Assigned Numbers Authority) latin1, except that IANA latin1 treats the code points between 0x80 and 0x9f as “undefined,” whereas cp1252, and therefore MySQL's latin1, assign characters for those positions. For example, 0x80 is the Euro sign. For the “undefined” entries in cp1252, MySQL translates 0x81 to Unicode 0x0081, 0x8d to 0x008d, 0x8f to 0x008f, 0x90 to 0x0090, and 0x9d to 0x009d. I can kind of understand the decision, but making it the default over utf8 is aggravating if someone inexperienced with character sets gets his hands on it first.
|
# ? Dec 20, 2013 18:13 |
mjau posted:Be careful with that though, it's not exactly the same. If bar evaluates to false, the Lua code will always give you baz. True, luckily Lua only has two falsey values, "false" and "nil", so it's generally easy to figure out if the bar expression can take those values.
|
|
# ? Dec 20, 2013 18:17 |
|
necrotic posted:Also neat: this is mysql (huzzah), so latin1 is an extend ISO-8559-1 charset used by Microsoft called cp1252. These forums return Content-Type:text/html; charset=iso-8859-1 But it's really cp1252. That was a fun thing to find out when certain characters were being parsed incorrectly in the awful app.
|
# ? Dec 20, 2013 18:18 |
|
necrotic posted:I can kind of understand the decision, but making it the default over utf8 is aggravating if someone inexperienced with character sets gets his hands on it first.
|
# ? Dec 20, 2013 19:19 |
|
Freakus posted:Note that mysql's utf8 doesn't support 4 byte characters. If you want that you need to use utf8mb4. Oh really? This is handy information, thanks!
|
# ? Dec 20, 2013 19:38 |
|
Inspired by the post about ebay's "eval" usage earlier, I decided to dive into the php codebase I support. 1900+ instances, most of which inside JS files, but here are some select PHP ones: php:<? //if (substr(trim($what), -1) != ';') { // $what .= ';'; //} eval('echo ' . $what . ';'); ?> php:<?php class Clense_SQL__Controller { /** * Clense table data * @param string $table_name * @param array $data_array * @static * @return void * @author [redacted] * @since 2009.08.04 */ static function clenseDataTable($table_name, &$data_array) { require_once('really/long/redacted/path/Clense_SQL_'.$table_name.'.class.inc'); eval('Clense_SQL_'.$table_name.'::clenseData($data_array);'); } } ?> security/db/security.class php:<? eval($str_to_eval); ?> EntranceJew fucked around with this message at 19:43 on Dec 20, 2013 |
# ? Dec 20, 2013 19:41 |
|
Dren posted:A list of examples of operators behaving in incongruous ways depending on their arguments is php-like. Ruby code:
Lua code:
xtal fucked around with this message at 01:50 on Dec 21, 2013 |
# ? Dec 21, 2013 01:46 |
|
Freakus posted:Note that mysql's utf8 doesn't support 4 byte characters. If you want that you need to use utf8mb4. MySQL is the php of the database world in all possible meanings.
|
# ? Dec 21, 2013 02:09 |
|
Hughlander posted:MySQL is the php of the database world in all possible meanings. Yup. We want to switch to Postgres but it will be a rather large project given how much data needs to move.
|
# ? Dec 21, 2013 02:37 |
|
xtal posted:
You're not trying hard enough
|
# ? Dec 21, 2013 03:11 |
|
This all seems like stockholm syndrome for languages where anything could implicitly and silently be null.
|
# ? Dec 21, 2013 03:49 |
|
I maintain a project that was full of plenty of horrors (the original author was...uh...), although fortunately most of them have been removed over time by either myself or our other developers. My favorite had to be this "pattern" (yes, it was used more than once) for processing rows:code:
I mean, it's incredibly stupid, but at least it will still process the correct rows, right? Well, one time it looked like this: code:
|
# ? Dec 21, 2013 04:04 |
|
xtal posted:I think it's the same in Perl, JavaScript and virtually every other language in use. Except for all those languages with strong static type checking, but who uses those.
|
# ? Dec 21, 2013 04:17 |
|
Color Gray posted:I maintain a project that was full of plenty of horrors (the original author was...uh...), although fortunately most of them have been removed over time by either myself or our other developers. My favorite had to be this "pattern" (yes, it was used more than once) for processing rows: To be fair, I do kind of wish that there was a way to elegantly combine the for loop with the foreach loop. If I use a for loop with an iterator or a get method, it's still an extra method call. I kind of wish there was something like: code:
|
# ? Dec 21, 2013 04:53 |
|
Volmarias posted:To be fair, I do kind of wish that there was a way to elegantly combine the for loop with the foreach loop. If I use a for loop with an iterator or a get method, it's still an extra method call. I kind of wish there was something like: Python has that Python code:
Although, the enumerate method is outlined as being this: Python code:
Jewel fucked around with this message at 05:03 on Dec 21, 2013 |
# ? Dec 21, 2013 05:01 |
|
Jewel posted:Python has that You win again, python!
|
# ? Dec 21, 2013 05:02 |
|
What are these strange 'for loops' of which you speak?code:
|
# ? Dec 21, 2013 05:09 |
|
|
# ? May 30, 2024 13:09 |
|
C# code:
|
# ? Dec 21, 2013 05:17 |