|
Plorkyeran posted:Luckily here we have a policy against empty catch blocks! Is this a trick post because that's not the biggest problem here.
|
# ¿ Dec 9, 2011 23:29 |
|
|
# ¿ Apr 20, 2024 05:41 |
|
Zombywuf posted:Also, found this on reddit, optimisation on modern CPUs is a horror unto itself http://stackoverflow.com/questions/8547778/why-is-one-loop-so-much-slower-than-two-loops Reminds me of one of the first BASIC programs I wrote as a 11-year-old. I can't even remember the syntax of the language, but the gist of it was like this: code:
It should have "snowed" randomly colored pixels, but in reality the pixels developed on the screen clear, diagonal, bands of color like this: "///". It totally boggled my teacher's mind.
|
# ¿ Dec 19, 2011 15:19 |
|
That's very interesting/scary.
|
# ¿ Dec 29, 2011 14:05 |
|
Yeah everyone like a good flying bear video, but for a game of such (indeed unprecedented) scale, Skyrim is remarkably low on bugs and doesn't have anything to do with this thread. I think I saw like 2-3 serious bugs in 140 hours of my playthrough. For content, I had a task of fixing an order management system recently. Made by one of the biggest software houses in the region while at it. They put it together using the same component they'd usually use to display tables of 0-50 rows, nd of course their clients didn't bother to check how it would act if the number of rows were 100k+. So every time the user opened the page, the system 1) read from the database into RAM every row of the orders table 2) read from the database into RAM every row of the products table 3) read from the database into RAM every row of the customers table then happily combined, ordered and filtered them as nice Java lists. Repeat the same procedure every time the user clicked anything on the page.
|
# ¿ Feb 2, 2012 22:26 |
|
Look Around You posted:This kid in my class asked me a couple days before the project was due (and a day or so before the final) if function parameters in C were passed by copy or not Correct me if I'm wrong (I never actually got around to learning C), but isn't the answer "either way you like"?
|
# ¿ Feb 14, 2012 16:26 |
|
Optimus Prime Ribs posted:Everyone has their preferred way to write code. It's not the biggest deal in the world, but the professor does have a point. You or some other dev might comment out or flat out delete the if statement, while forgetting about the bool gonnaLoseMarks = true;. code:
edit: Actually, depending on language it could make an even bigger mess if bool gonnaLoseMarks = true; was commented out instead. Something like code:
pigdog fucked around with this message at 22:04 on Mar 24, 2012 |
# ¿ Mar 24, 2012 21:56 |
|
Internet Janitor posted:"At age 59, every programmer has the indentation style he deserves." I don't know about braces, but I can dig the assignment operators being lined up. Looks kinda neat.
|
# ¿ Mar 28, 2012 06:40 |
|
Strong Sauce posted:Did they seriously hard code every special offer code they have? I hope not to sound like a contrarian jerk... But aside from general badness and not putting start and expiry dates in the code it's not necessarily a bad idea to hard-code promotions like that, depending on circumstances. Making a nice administration UI for something like that an order of magnitude more work. If an offer is complex, then making it configurable is even more complex. If it's a small company, the number of offers and options are limited enough to have a grasp of, and it's easy to deploy new versions, then it may very well be easier to tell the VB programmer to update the code and redeploy. As opposed to spending a lot more resources, and dealing with a lot more integration, security and maintenance issues, to develop an interface for non-technical people who may end up needing the help of technical people regardless. At the very least they seem to have some code reuse going on, and have the offers separated into distinct methods/objects. Come to think of it, that code could look far worse. Maybe I'm just jaded because the core "god" system in my company is extremely configurable, and all sorts of cool offers can be created on the fly, but the code itself is horrible and we're reliant on a subcontractor for more than a decade to keep the mess together. The accomplishment of the year was to get all that PL/SQL code finally on version control.
|
# ¿ Mar 29, 2012 08:23 |
|
Sulk posted:http://pastebin.com/WEBKaCWK Come to think of it, this is absolutely a textbook case of code that needs refactoring, such as... - introducing constants because gently caress me, those numbers - sort those constants (numbers) out to bring out actual business logic in human readable fashion - get rid of global variables - ... wait what, these aren't just global, but global session variables? - Call <whateverDiscount>(Session("key"), pIdDbSessionCart) repeated a million times means abstraction that simply glares in your face - which first demands refactoring static functions into object and methods - and there's ever been a chance to split a piece of code up into meaningful parts that do one thing, then stuff like code:
Etc. However, I don't hate that piece of code. There are some good things in it. I like how they've used nice and meaningful function names, and have grouped up offer-specific functionality in them. So for all its faults and obsession with offer codes, the code, and the business logic it's trying to convey, is almost readable even at this state. With a good refactoring it could probably flow rather nicely. Meanwhile, since the offers are separated into methods that work on (presumably) the shopping basket object, they can contain arbitrarily complex rules. Not just static discount of x% or $x, but stuff like "on Fridays offer every 3rd item free to all grocery items as long as the basket has a Pepsi in it, but only once a hour". The biggest functional deficiency seems to be the lack of automatic expiry and application of offers, which would apparently be clumsily solved by deploying new versions whenever anything changes. edit: Come to think of it, the functions implementing the discounts, such as xpTillerDiscount50(), may actually include the relevant time constraints in them, and only do anything if the offer isn't expired. pigdog fucked around with this message at 16:30 on Mar 29, 2012 |
# ¿ Mar 29, 2012 15:07 |
|
I was trying to understand what the code even does, but my mind started to wander off with all the anal1.put() and anal2.put() lines. edit: Have to say, putting a test suite in the main[] method of a class is a pretty novel idea. Pretty much exactly like writing real unit tests... except for the part where the user has to verify all the results manually, instead of like, having the computer do it. pigdog fucked around with this message at 22:38 on Mar 31, 2012 |
# ¿ Mar 31, 2012 22:28 |
|
Suspicious Dish posted:The anal1.put and anal2.put lines are just test data for the main function.
|
# ¿ Mar 31, 2012 23:11 |
|
Yeah, it's a pretty legit coding horror. I mean, why would anyone really need such a data structure with such a lookup scheme in the first place? I bet the code that uses that class looks no better. It was mentioned that performance is a problem, so presumably the actual FancyArray objects are fairly large. Where does the data it is supposed to parse come from? If the data set is reasonably small, as in it has to fit in memory like a FancyArray would, then why isn't it represented as sensible objects? If the data set is large enough, then why isn't it stored and queried from a database, and regardless, represented as sensible objects in the code? It's like, whoever wrote this knew they needed some hierarchical way of storing and accessing data, but didn't really trust this newfangled objects, collections, and encapsulation malarkey. pigdog fucked around with this message at 06:36 on Apr 1, 2012 |
# ¿ Apr 1, 2012 06:34 |
|
I don't know anything about Objective-C or Macs, so can't say what I know the context and what it's good for so well, but from where I'm standing it doesn't seem very neat, either. Perhaps it's a peculiarity of that language and environment, i.e. requirements to support easy scripting, and it can also be considered stable and explicit way of doing things that a developer can rely on and simply needs to learn. But not necessarily something that seems desirable to replicate in normal code or object models. I mean, in Java you could make an object's fields public and explicitly read/write to them (or use reflection), and there are cases you might even see that as desirable (ie setting up unit tests), but you can also accomplish the same while maintaining encapsulation by setting them to default or protected scope instead of private, and having your unit test live in the same package as the code, though obviously in a separate file and directory. Meanwhile, even if the class was optimized better, I can't quite imagine the problem to which I'd say "yeah, the best way is to use a FancyHash to do this". pigdog fucked around with this message at 17:10 on Apr 1, 2012 |
# ¿ Apr 1, 2012 09:35 |
|
Seeing as he has 3700 viewers at the moment, I suppose plenty of people do.
|
# ¿ Apr 7, 2012 21:32 |
|
His game is a very good example though of a quality product. Code quality isn't in fact about how good the code looks, how reliable it is or whether it runs as fast as it could -- it's about whether people would want to use it. In this case, whether they'd want to play the game. Even it (in comparison) runs like rear end and is written badly, the game has still sold millions of copies and is by any means an unabashed success. The fact is that people don't care about the code or the performance being terrible, or at least don't care enough not to play the game. Other developers may look at his code and find it terrible, but it doesn't matter while he's laughing all the way to the bank. That's a serious lesson to consider. People with different background put different importance on different aspects of software. Things that a developer may consider important, such as cleanliness of code, reliability, etc, may but may also not necessarily be what the customer, or the users consider important. Don't get me wrong, I love fully tested, clean and bulletproof code, but there may be cases where making tradeoffs is the right thing to do.
|
# ¿ Apr 8, 2012 22:24 |
|
quote:Nobody here is lamenting that Notch did it first or that we could do it better. It's coded badly. It is a thread about bad code. Therefore, we are talking about it. It's the same thing for PHP. And RMS. Just because someone did something good/cool/popular/etc does not make that product immune to criticism. quote:'Fitness for purpose' is not the same thing as quality. Consider PSN, before last April. Millions of people wanted to use it. Sure, Sony was transmitting and storing unencrypted credit card numbers, but nobody cared - information security just wasn't important to their customers. Hell, even after the breach, most people blamed the "hackers" for everything. By your definition, PSN was a very good example of a quality product. Do you think Visa and Mastercard agree with you? In any case, if we were to say PSN was one of the many gaming and communication networks available and there was real competition, then the quality would include top notch security, as security of credit card information would certainly be a huge factor in choosing a gaming network. Hell, it's hard to imagine a situation where security over handling credit card information wouldn't be. If you were to build a network like PSN and you couldn't make it produce value, because Visa and Mastercard would deny you and/or the customers would sue the crap out of you, then no matter how gold-plated your code is, you are doing it wrong. On the other hand, performance of a game like Minecraft is provenly a smaller factor than fellow developers may think.
|
# ¿ Apr 9, 2012 06:30 |
|
quote:Because clearly if something's successful it's automatically perfect, right? Ultimately you don't code something like this for coding's own sake. Succeeding in writing software that people would buy is a higher level goal than writing perfect code. The latter is ultimately the means to attain the former.
|
# ¿ Apr 9, 2012 07:27 |
|
That's correct: if people buy your cheap and lovely candy and you're making profit, then you must be doing something right. McDonalds is a pretty successful company, wouldn't you agree? You're not running the factory for the candy (instead you could just go to a store and buy any candy you personally like), but as with any enterprise you're running it for profits. But sorry for the derail.
|
# ¿ Apr 9, 2012 07:39 |
|
Look Around You posted:I am not Notch. I am not speaking for Notch. I am speaking for myself. I don't give a drat whether or not he's making money off of it, it doesn't affect me one bit. I'm a lot more interested in theory than in making money anyway. On the contrary, I'm perfectly aware of what this thread is about. Minecraft's success story in my opinion augments it brilliantly. Developers may get too caught up in quality and gold-plating that they don't realize, or forget, what's actually important: for the code to provide some value for someone. Personally, I'm totally obsessed with writing clear, optimal and bulletproof code with test-driven methodologies, but there's no way to argue with Minecraft's success. Something like Skyrim has been and has to be lovingly, skillfully and painstakingly crafted, but from the other end, noone would gold-plate or test-drive a shell script they would only use once. Notch has found his own sweet spot between speed, skill and quality, and even if it's not quite as well made as Skyrim or not quite as hacked together as a single-use shell script, he has succeeded and thus done it right in his own way.
|
# ¿ Apr 9, 2012 07:56 |
|
the ultimate PHP rant posted:I have heard a great many stories about the PHP interpreter and its developers from a great many places. These are from people who have worked on the PHP core, debugged PHP core, interacted with core developers. Not a single tale has been a compliment.
|
# ¿ Apr 10, 2012 06:41 |
|
You'd base your procedural generation on something else rather than buggy system-specific random, as in by definition unpredictable, number generation. Something you'd include as a part of the codebase for the game.
|
# ¿ Apr 11, 2012 10:28 |
|
The Gripper posted:Reminds me of this: It's not as funny as it could be, because Erlang is actually pretty awesome.
|
# ¿ Apr 19, 2012 09:38 |
|
baquerd posted:Every so often explicit code jumps are useful, here's a fragment I recently used one in. While you can write this block in other ways, I like the flow better this way. I don't have a compiler at hand at the moment, so this is straight from the hip, but I think this could be written as code:
|
# ¿ Apr 19, 2012 22:23 |
|
If you're doing something with the XML, you'd almost certainly expect it to be in a particular format. You can define that format in a .xsd schema, afterall that's what they're for. It's still a good idea define a schema for the XML data format even if you use a generic parser of some sort, if only for testing and documentation purposes.
|
# ¿ Apr 27, 2012 22:12 |
|
Bhaal posted:In terms of data format I wouldn't say XML is necessarily a terrible way to go in this case, BUT: quote:A better solution, though involves a lot more dev time, is to make an editor for them. It's on the fly validation as you can have the editor demand input where input is required, generate required child nodes and so on, so your user doesn't get lost in the weeds on your data structures. Also they don't have to worry about syntax or any of that meta data and instead just fill in the pertinent stuff. You could do this in a native app or make a page that builds out form elements with js/jquery/etc, submits to your server, and you feed them back the resulting xml. Note: I don't know how much use those xml documents will see from your userbase, though, so putting in the time to make a tool like this may not be an efficient sub-project to work on if you don't anticipate a lot of user generated documents. If 1 in 10 of your dedicated userbase will ever seriously dabble in it, maybe it's best to provide clear documentation & examples and leave it at that.
|
# ¿ May 2, 2012 22:27 |
|
Janin posted:Also, once you're in your handler, you'll have to spend several more milliseconds establishing database/rpc connections, loading/parsing templates, and generally doing setup work that a single-process server only needs to do once.
|
# ¿ May 6, 2012 07:37 |
|
Zombywuf posted:I... I'm sure you're trolling, but that's not very funny. And if you're not, then the last pages are just . Zombywuf posted:CGI is a perfectly good way of running code.
|
# ¿ May 6, 2012 18:13 |
|
Speak for yourself, using languages other than English with computers used to be a lot bigger pain in the rear end.
|
# ¿ May 9, 2012 21:16 |
|
Golbez posted:It's basically: quote:This one is easy enough, using mktime(). Just provide the stuff getdate() gives you to it and run the returned timestamp through getdate() again, adding a day if wday == 0 || wday == 6. Since mktime allows days beyond the end of a month (which go into the next month) this is pretty simple even for a braindead solution I just came up with in 30 seconds. pigdog fucked around with this message at 19:26 on May 10, 2012 |
# ¿ May 10, 2012 19:22 |
|
Zamujasa posted:(The other, more plausible solution is just turning all input to lowercase letters, but given the "security" of several large corporations these past few years, I suspect the worst.) Pretty sure that's how they do it. It's just a game password, and not brute-forceable (against their servers), so meh, reasonable enough.
|
# ¿ May 23, 2012 21:29 |
|
What if there are 500 items in the category, but the page is set to display only 20 of them at a time? What if some of the items don't have images associated with them? Y'all should just get rid of the hardcoded and un-i18nable "Total Items:" and let #CatTotal refer only to the number. pigdog fucked around with this message at 08:45 on Jun 6, 2012 |
# ¿ Jun 6, 2012 08:41 |
|
darthbob88 posted:Apparently the site's set to display at least 40 items on a category page, so that's not an issue. AFAIK, all the products have images, so my solution would still work. They may be blanks reading "No Photo Available", but every product has an image. And of course it doesn't really matter anymore, since the new system doesn't care about how many items are in a category. Your boss's: - expects the string "Total Items: <number>" with no regard to i18n Yours: - expects every product to have an image - expects every product to have one image - expects products without images to have blanks - expects said images to have ID of "qv_*" (though perhaps that's a firm specification?) - expects the number of images per page to equal the number of items per category (all products to be displayed at once) - presumes the question to be whether or not there were more than 20 items in a category, and the actual number to be irrelevant If that's just one-time scrape, then cool, it doesn't matter terribly much. Yet I feel your original solution involves many more unobvious assumptions, each which have potential to introduce bugs and disparities if the context changed. Even on the link you provided, your solutions would provide different counts already.
|
# ¿ Jun 7, 2012 08:42 |
|
evilentity posted:How the gently caress people conclude that 2000+ lines of same code with 3 variable things is a good idea? Not that it couldn't be expressed better, but that code is very probably generated.
|
# ¿ Jun 19, 2012 18:56 |
|
Zombywuf posted:This makes you sound like someone who has never used Perl. quote:Unfortunately, there is currently no way to tell Perl that incoming data from an external file is Unicode; while you can write Unicode data out to a file, you cannot read Unicode data back in again. While you can work around this with tr///CU, it's obviously a serious shortcoming, which we hope will be addressed soon. It was a horribly broken mess. In its quest for backwards compatibility and doing the right thing intuitively, it made guesses about the character set the text it manipulated was in. They weren't very good guesses. If you got tired of the brokenness, said "gently caress it" and tried to revert to previous approach of use bytes;, then external libraries (like XML parsers) broke in turn. One of the greatest such "features" I wrestled with was when you got everything right and it started outputting a page in a correct encoding and everything was peachy... but upon inserting a substring or encountering some character it decided it had guessed wrong and changed the encoding on the fly. Had a fun time solving bug reports saying that half of some page displayed properly, but the other half of the page was in gibberish. They gradually improved the stuff and somewhere around pigdog fucked around with this message at 21:23 on Jun 21, 2012 |
# ¿ Jun 21, 2012 21:01 |
|
shrughes posted:Floating point for monetary values isn't necessarily a coding horror.
|
# ¿ Jun 30, 2012 23:54 |
|
C coding makes one p. mad.
|
# ¿ Nov 25, 2012 18:13 |
|
Most of the discussion here really stems from the fact that different people argue over rules which apply to different levels of the Dreyfus model. The rules that you'd set for a beginner or advanced beginner are different from these that apply for an expert. For a 2-year-old the rule is simply "DO NOT TOUCH THESE WALL THINGS, OUCHY OUCHY". For a 8-year old the rule might be, "Never touch or shove anything into the wall outlets except for proper plugs on things". For an adult the rule may be "Don't mess around with the outlets except when you're sure you switched the power off at the mains". The next level may be "Well you may touch one of the wires even when the power is on, as long as you're isolated from the ground and not touching any other wires" Same thing for anything code-related. It makes better sense to offer the beginners concrete and hard rules, which they may grow out of, rather than trying to explain the intrinsics of electricity to a 2-year-old.
|
# ¿ Nov 26, 2012 08:24 |
|
Extortionist posted:I came across something like this today, in some older code written by one of our more senior programmers that's still being used for live, production work: quote:Every time I look at this I am increasingly more appalled that this guy is apparently using an editor with a <35 character line limit. pigdog fucked around with this message at 10:46 on Nov 30, 2012 |
# ¿ Nov 30, 2012 10:44 |
|
Hughlander posted:Could be worse... Could be You could put actual exception handling code inbetween these { } at the catch statement, and for most programs, end up with excellently handled exceptions.
|
# ¿ Dec 1, 2012 16:16 |
|
|
# ¿ Apr 20, 2024 05:41 |
|
This is a very nice article on how to use exceptions: http://www.sysart.fi/news/9/37/Exceptions---the-big-picture/d,artikkeli
|
# ¿ Dec 2, 2012 14:28 |