|
fritz posted:I found a line in some academic C code just now that has 5 "="s, two arithmetic operators, and a []. Sounds like another victim of K&R.
|
# ? Jul 16, 2014 09:49 |
|
|
# ? May 17, 2024 13:37 |
|
fritz posted:I found a line in some academic C code just now that has 5 "="s, two arithmetic operators, and a []. a += b[0] == c + d == f What do I win?
|
# ? Jul 16, 2014 10:04 |
|
eithedog posted:a += b[0] == c + d == f Mother of God.... Newlines, motherfucker, do you speak it? Unless you're just trying to be cute, there's no reason to put all that crap on a single line. dealmaster fucked around with this message at 14:09 on Jul 16, 2014 |
# ? Jul 16, 2014 14:07 |
|
eithedog posted:a += b[0] == c + d == f The shame of having written that.
|
# ? Jul 16, 2014 14:10 |
|
Edison was a dick posted:i = i++ is undefined behaviour in C, so Java could have inherited that feature. No, it's perfectly defined, it just doesn't increment the variable. The guy who wrote that was a SQL developer that got assigned some Java development, so he didn't realize all you needed to do was ++i; and be done with it. EAT THE EGGS RICOLA posted:Someone just handed me a ~7000 line javascript thing to look at and make major changes to by tomorrow at the latest. Every variable and method has a two or three character random name. For example something I might call getElementId is called sn. This type of poo poo is the worst. I remember getting added to a code review that included over 90 files after the project was completely done and this guy worked on it all by himself. Writing to the console everywhere, lovely design, bad variable names, Pokemon exception handling, etc. But the code was already being signed off by the business, so it was too late to go back and change everything. Why do we get added to reviews like this at the very last second when nothing can realistically be done??? dealmaster fucked around with this message at 14:14 on Jul 16, 2014 |
# ? Jul 16, 2014 14:11 |
|
dealmaster posted:Why do we get added to reviews like this at the very last second when nothing can realistically be done??? So that the person who's actually responsible for that situation has someone to pass the buck to when it all comes crashing down. If you're not able to actually veto the change, it's not a real code review, and you should probably make sure it's not your responsibility by stating that you have reservations and <person who punted the review to you> can sign off on it if they think it's good.
|
# ? Jul 16, 2014 14:31 |
|
why is this so funny?
|
# ? Jul 16, 2014 14:43 |
|
Jabor posted:So that the person who's actually responsible for that situation has someone to pass the buck to when it all comes crashing down. Yeah I knew it was purely a cover-your-rear end thing, my question was more me raging at stupid coworkers. I was able to make him implement many of my changes including some changes in design, but not everything was done, unfortunately. Gotta meet that arbitrary release date, yo. You know, the date that someone promised someone higher up months and months ago without consulting the developers at all. My coworkers and I like to call those rear end-dates. There are also rear end-metrics, rear end-numbers, and rear end-requirements that all originate from someone's rear end and never went through any formal process at all.
|
# ? Jul 16, 2014 15:28 |
|
eithedog posted:a += b[0] == c + d == f How about, a ^= (b[0] == c) ^ (d == f); which doesn't seem unreasonable at all?
|
# ? Jul 16, 2014 16:10 |
|
There's no benefit to writing it like that. Use intermediate variables with clear names and let the compiler figure out how to optimize stuff.
|
# ? Jul 16, 2014 17:23 |
|
Snapchat A Titty posted:There's no benefit to writing it like that. Use intermediate variables with clear names and let the compiler figure out how to optimize stuff. Even if the compiler doesn't optimize it as well as you do, I'd rather have readable code that takes a few nanoseconds longer to execute.
|
# ? Jul 16, 2014 17:29 |
|
I guess I'm the horror because I find that readable
|
# ? Jul 16, 2014 17:48 |
|
Voted Worst Mom posted:How about, But also doesn't do the same thing?
|
# ? Jul 16, 2014 18:53 |
|
If you knew what b, c, d, f, and a were, that would be perfectly fine.
|
# ? Jul 16, 2014 19:03 |
|
Subjunctive posted:But also doesn't do the same thing? There wasn't a code sample posted. They are both guessing what it could have been based off the description.
|
# ? Jul 16, 2014 19:44 |
|
And everyone's cheating the "5 =" by assuming a single assignment and two comparisons. a = (b=4)+(c=6) +(d=e=0);
|
# ? Jul 16, 2014 19:52 |
|
You asked for it. code:
|
# ? Jul 16, 2014 20:10 |
|
fritz posted:You asked for it.
|
# ? Jul 16, 2014 20:33 |
|
fritz posted:You asked for it. So he intended to write: vmin = input[k0]; k = k0; kminus = k; umin = lambda umax=vmin+umin-vmax;
|
# ? Jul 16, 2014 20:41 |
|
code:
|
# ? Jul 16, 2014 20:44 |
|
JawnV6 posted:And everyone's cheating the "5 =" by assuming a single assignment and two comparisons. Seriously stop people. This is like the code golf of horrors.
|
# ? Jul 16, 2014 20:51 |
|
Flagrama posted:There wasn't a code sample posted. They are both guessing what it could have been based off the description. Ah, my mistake.
|
# ? Jul 16, 2014 20:54 |
Coylter posted:Well, let's just say this made my day. This gentlemens, is part of the server code of something important. I enjoyed this code a lot, because first you do a quick scan and see the giant if pyramid, then you read it again and realize what it's actually for, then you read it again and see how it's doing it. And each time you lose more faith in humanity. Also, chrNombre.
|
|
# ? Jul 16, 2014 21:52 |
|
Coylter posted:
Has the writer of this never heard of a regular expression? Jesus Christ.
|
# ? Jul 16, 2014 22:00 |
|
dealmaster posted:Has the writer of this never heard of a regular expression? Jesus Christ. In fairness, regular expressions are pretty horrific themselves.
|
# ? Jul 17, 2014 01:59 |
|
xtal posted:In fairness, regular expressions are pretty horrific themselves. No they are not. The "...now you have two problems " meme is garbage. A regex is basically a deterministic finite automaton (DFA) and your string is the tape it runs on. As simple as that. Most people who struggle with regex do because they don't bother testing their regex in Notepad++ or Sublime or what have you.
|
# ? Jul 17, 2014 02:16 |
|
xtal posted:In fairness, regular expressions are pretty horrific themselves. Yeah, "now you have two problems." That code's not horrible to read once you squint past the boilerplate. If it were chained with && it would be pretty decent. Maybe better with the equivalent of a string stream or sscanf? ^^^ Regular expressions are a classic example of write-only code, especially without Perl's /x readability help. This case is simple enough that it could be OK, but it's a dangerous path. I've worked on regex engines (JS's replace-with-function-call is my fault), and I have to think pretty carefully to make sure I'm thinking about greed and backtracking correctly with all but the simplest stuff. (Most regex engines are not actually regular expressions, and they all vary a bit in syntax or semantics, which also hurts understanding after the fact.) Edit: testing in Sublime is great for the cases you think of, but exploring that space effectively is hard. Subjunctive fucked around with this message at 02:23 on Jul 17, 2014 |
# ? Jul 17, 2014 02:17 |
|
Subjunctive posted:Yeah, "now you have two problems." I disagree that regex is write-only. A regex is literally the machine that will match your string, as in what you see is 100%, no doubts about it, what you get. Not being able to figure out a regex instantly is not a failure of regex. A simple line of regex is the equivalent of pages of code in your language of choice. That's the point of using regex after all. If there is a more readable regex equivalent please share. (Note: more characters to type != more readable)
|
# ? Jul 17, 2014 02:35 |
|
There's two problems (heh) with regexes that lead to their unreadability when used as a parser for human input. The first is that human input is messy. Phone numbers are going to be 123-456-7890. Or they might be (123) 456-7890. Or just 456-7890. Or maybe even +11234567890. And then you can easily replace spaces with dashes or parens or just nothing in any number of configurable ways to meet certain conventions. A regular expression that matches "phone numbers" has to take into account these different customs is going to be complex, because the original problem is really complex. The second problem is that traditional regular expression languages don't have any inherent composability. There's no way to say delimiter = '-' | ' ' | ''; and then use (\d{3})? $delimiter (\d{3}) $delimiter (\d{4}). Because of this, you also see a lot of clever trickery in common regex syntax to group some parts together, and a lot of "code golf" that makes it dense and unreadable. Trying to understand a regular expression is like reverse engineering assembly code, almost. The problem with regexes isn't that they're inexact. It's that the user experience of them is designed in such a way to lead to discourage breaking problems down and readability, and increase cleverness.
|
# ? Jul 17, 2014 02:48 |
|
I agree that composability would be a nice feature to have. But I don't agree with the rest. If your matching rules are complex, why are expecting a simple nice to read solution? E: the unreadability of the regex is not because it's regex. It's because your rules are complex. (Try matching with your own favorite language, heck try writing the matching rules in English and see).
|
# ? Jul 17, 2014 03:11 |
|
I'm saying that our current regular expression representations could go a long way towards encouraging more readability and composability, and right now they fail in those aspects, because every character matters. Googling for "phone number regex", the first result I found is: ^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$ Given enough time, you can break apart what it's doing. It's almost like compiler output, and that it really has to be reverse-engineered. I won't clean up that, since this is a dumb forum post and I have work tomorrow in the morning. But imagine an alternate representation: code:
|
# ? Jul 17, 2014 03:23 |
|
As I saidShinku ABOOKEN posted:I agree that composability would be a nice feature to have. I don't want to continue the derail any longer, and I also don't want people to avoid the right tool for the job. My point is if your problem is solvable by regex just use regex and call it a day. Don't be superstitious.
|
# ? Jul 17, 2014 03:50 |
|
Suspicious Dish posted:
Lua code:
|
# ? Jul 17, 2014 05:35 |
|
Regexes are fine and cool for the trivial case, and you should probably use them, with the major caveat that you should throw them away with extreme prejudice as soon as your case becomes non-trivial.
|
# ? Jul 17, 2014 07:44 |
|
Edit: Instead of contributing, I made a snide comment in favor of regexes. My two cents is use them, let the golfers play golf and then paste their string into your code. Portability in favor of readability, because I wouldn't read it anyway, I don't care enough about international numbers or trailing extensions, and would botch the implementation if I tried. To contribute: The reason I'm in a snide mood is because yesterday my client came back to me with a recurring problem. We have a yellow rectangle on the main page, where there's a logo, and text to the right of it. Again she said that the way it renders in her browser, Firefox, is as a rectangle with a logo in it, and a scroll bar on its right hand side. If she scrolls down, there's the text, hidden away. So I changed the settings and tested the site in Firefox and Chrome and Safari and IE and IE10 and IE9 and can't duplicate the issue, so every time I say "It looks fixed" I mean to say "It definitely isn't doing that under any normal circumstances, and I re-solved the problem from a different direction so maybe that helped your strange computer". But yesterday, while on the phone talking about the website, she saw the front page and yelled "Oh, it's fixed!" Then proceeded to say "But when I zoom in I still get the scroll bars". Oh. Pythagoras a trois fucked around with this message at 15:34 on Jul 17, 2014 |
# ? Jul 17, 2014 15:05 |
|
code:
|
# ? Jul 17, 2014 16:12 |
|
Subjunctive posted:Yeah, "now you have two problems."
|
# ? Jul 17, 2014 17:02 |
|
Suspicious Dish posted:I'm saying that our current regular expression representations could go a long way towards encouraging more readability and composability, and right now they fail in those aspects, because every character matters. While I get your point, what you wrote doesn't match the same state machine as the regex, that's why the regex is so complex. Your test input isn't a valid phone number. Area code and exchanges can't begin with 1. The regex posted matches with or without an area code. Hell the *SPECIFIC* one you listed also allows for an extension at the end optionally. That's why they're useful. Modify yours so that '555-0134 ext 1321' is allowed, but 123-456-7890 isn't for some fun.
|
# ? Jul 17, 2014 17:58 |
|
Suspicious Dish posted:The second problem is that traditional regular expression languages don't have any inherent composability. There's no way to say delimiter = '-' | ' ' | ''; and then use (\d{3})? $delimiter (\d{3}) $delimiter (\d{4}). Because of this, you also see a lot of clever trickery in common regex syntax to group some parts together, and a lot of "code golf" that makes it dense and unreadable. Trying to understand a regular expression is like reverse engineering assembly code, almost. Lex is 39 years old. How much more traditional can you get?
|
# ? Jul 17, 2014 18:21 |
|
|
# ? May 17, 2024 13:37 |
|
Suspicious Dish posted:Googling for "phone number regex", the first result I found is: ^(??:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$ That regular expression doesn't even match my phone number, anyway, so for all that complexity it still isn't good enough. It doesn't even match it if I "internationalise" the number by deleting the leading zero and adding +44.
|
# ? Jul 17, 2014 19:23 |