|
TasteMyHouse posted:He's assigning to a final variable. I guess final as applied to array variables in Java doesn't make the elements of the array itself final? Or did this even compile? A final variable in Java is a special trick that allows closure-like behavior. See this page for more information.
|
# ¿ Nov 30, 2011 21:25 |
|
|
# ¿ Apr 19, 2024 23:52 |
|
NotShadowStar posted:Every single one of them should be called out and publicly shamed. They took the brilliant Smalltalk language and hosed it all up because they thought that they couldn't sell something to aspergers filled engineers if it didn't look tangentially like C++. I should take the time to point out that there are three things that we call Java:
Suspicious Dish fucked around with this message at 02:13 on Dec 1, 2011 |
# ¿ Dec 1, 2011 02:07 |
|
Aleksei Vasiliev posted:
I hope you learned your lesson.
|
# ¿ Dec 1, 2011 21:37 |
|
DotFortune posted:
Switch statements are jump tables, so they're faster than if statements!
|
# ¿ Dec 2, 2011 02:42 |
|
I know Zope is all sorts of terrible ideas and bonghits, but this is just atrocious: minjson.py. It tries to use Python's tokenizer to parse JSON. It works as well as you think it would. Considering I've made a hand-written JSON parser in an hour to win a bet, there is no excuse for this. (The bet was related to Prototype's use of regex to validate JSON and then parse it using eval(), which is a horror in and of itself. I bet money that there was no excuse -- the JSON spec was easy enough to hand-write a recursive-descent parser for in an hour. I won.)
|
# ¿ Dec 7, 2011 09:15 |
|
evensevenone posted:I really liked the period of time where the harder/uglier it was to do something in CSS the more likely common it was because 98% of the CSS tutorials on the web were three-column layouts and rounded corners. I still think CSS is terrible for layout. There's 1000 different ways to "center something", and they all have their own drawbacks. It's amazing to me that there's a whole society of people who have been brainwashed into believing that position: absolute; top: 50%; left: 50%; margin-top: -300px; margin-left: -400px; is better than <center>. I'm all for separation of content and markup, but what I feel CSS needs is horizontal-position: center; vertical-position: center;, which the browser would do all the correct math to center the element relative to the parent. I've heard there's a float: center; in CSS3, and there's that new fancy flex box stuff, so I guess there's things to look forward to.
|
# ¿ Dec 8, 2011 03:16 |
|
NotShadowStar posted:
Only works with a specified width, and now you need a wrapper <div> to add a margin.
|
# ¿ Dec 8, 2011 15:01 |
|
wwb posted:That isn't horribly bad code there -- they are cleaning up using the finally block. VB.NET didn't have using(){} until the VS2010 version AFAIK so it makes sense. I believe you can have a Try...Finally without the catch in the middle, so you don't have to silently ignore exceptions.
|
# ¿ Dec 9, 2011 22:20 |
|
Markov Chain Chomp posted:The rule of thumb is to prefer more abstraction, not less, unless you have a very particular reason for doing so. I apparently have very good particular reasons all the time, then. Furthermore, SQL is already an amazing abstraction. It completely takes out of the picture of how to store data and just lets you write "please insert this data, thanks". All an ORM does is let you pretend that tables are classes and rows are objects and columns are members. Not only are there cases when pretending things are objects is not OK, there are cases where ORMs do not provide the expressive power of raw SQL. Just like compiling from a high-level language to assembly restricts you to the subset of features that the high-level language has, compiling from an ORM's language to SQL restricts you to the subset of features that the ORM has. And because SQL is a unique language in that it lets you express what you want to do, not being bogged down by implementation details, you're cutting out a lot of features when you restrict yourself to an ORM's feature set. For simple CRUD operations, this is perfectly fine, but when you start wanting asking complex queries like "what's the average of all the star ratings that customer A, B and C for products they ordered in the last thirty days that shipped in under a week?", you start pushing the limits of the ORM. Yes, this was a real report that I implemented two weeks ago.
|
# ¿ Dec 10, 2011 04:27 |
|
Bozart posted:While I haven't used whatever that stuff was, using exclusive upper bounds on ranges is great for things like spans of time. There would probably be an object for that which would attempt to do this for you. But anyway here's an example: you have a function that will tell you if a given date and time are considered "off peak" for the eastern us power grid. You want to know how many off peak hours are within a given week, say, the week starting 12/11/2011. Then you can call this function over the range [ 12/11/2011 .. 12/18/2011 ) and there is no ambiguity about the first hour of 12/18/2011. I don't want to use a language designed by you. Date literal syntax? And yes, it seems terrible that we have two range syntaxes, when we only need one. Also, somebody decided to take Sinatra, port it to Perl, and call it "RESTful". The result? Mojolicio.us
|
# ¿ Dec 13, 2011 06:08 |
|
For some reason, it's been picked up in JavaScript because it calls [[ValueOf]] and does nothing else. So you'll see stuff like:Dumb JavaScript Tutorials posted:You can use +new Date to get the current time in milliseconds! not realizing that it's just the same as (new Date).valueOf(), or (new Date) + 0 or something like that. Oh, and because you can overload it in Python, you can do some fun tricks with it. In fact, my ailment.py is a coding horror in and of itself. Just for some mindless fun.
|
# ¿ Dec 20, 2011 04:30 |
|
AlsoD posted:As somebody with no database experience whatsoever, how would a thread with its posts be represented? Each sub-forum a table, each thread a column and each new post a row? That is not how databases work. You could model it in three different tables: forums, threads and posts. A post would have a foreign key column to a thread, and a thread would have a foreign key column to a forum.
|
# ¿ Dec 31, 2011 02:59 |
|
kitten smoothie posted:Thankfully this "feature" is no longer enabled by default in PHP. In PHP5 they split the access controls out for fopen() and include(), so under the default configuration, you can fopen() a URL but you cannot include() a URL. allow_url_fopen doesn't stop it, because it still allows php:/// URLs: code:
|
# ¿ Jan 2, 2012 22:44 |
|
There's also the horrible thing about time: it's not a function, continuous or not. There are dates and times that have never happened. There are dates and times that have happened twice or even thrice.
|
# ¿ Jan 7, 2012 02:08 |
|
Sure, you can do that. You would need a lot of crazy timezone data like the link ymgve posted. The problem is being able to have a user say "I want an alarm to go off at 1:30 PM on November 4, 2012" and convert that back into a timestamp.
|
# ¿ Jan 7, 2012 04:49 |
|
If people haven't written a polyglot yet, it's quite fun. Here's a Python and C polyglot I wrote a little bit earlier:code:
|
# ¿ Jan 15, 2012 05:27 |
|
The big problem with Python 3, for me at least, is that its handling of bytes is really, really terrible. Read this bug report, for instance. The incorrect responses from the Python maintainers are embarrassing.
|
# ¿ Jan 19, 2012 00:00 |
|
Even better: http://codepad.org/8BAzFDfiphp:<?php if (true) { function foo() { echo "php"; } } else { function foo() { echo " sucks"; } } foo(); if (true) { function bar() { echo "php"; } } else { function bar() { echo " sucks"; } } bar(); php sucks It's dependent on the whitespace at the beginning of the line, too.
|
# ¿ Jan 19, 2012 06:16 |
|
Soup in a Bag posted:I just tried Plorkyeran's first example in 5.1.2 and it did print 'php sucks'. code:
|
# ¿ Jan 19, 2012 07:36 |
|
yaoi prophet posted:Haha, apparently by default exit is bound to a Quitter object whose __repr__ is that 'Use exit()' message. Right. The reason it doesn't just quit on __repr__ is because anything that calls repr() on it will quit the program. There are quite a few tools in the stdlib that do, so using those tools on the global scope shouldn't just abort randomly.
|
# ¿ Jan 21, 2012 23:04 |
|
Move over AES and PGP, it's time for "The most secure data cryption program in the world": KRYPTOChef! AES and PGP are public algorithms, which means that anybody can study them to learn how they work and decrypt any file. KRYPTOChef is different: KRYPTOChef posted:It will be a self-developed by me (ONLY) in KRYPTO used (OTP encryption method) is used. It even has proof of its security! Watch: KRYPTOChef posted:Proof of the Krypto security ! For those not versed in idiot, this says: "The permutation of files with 18,033 bytes is a number with over 43,424 places."
|
# ¿ Jan 23, 2012 01:55 |
|
There's another whole side of metaprogramming: C even has a side of this, since it has no OOP by default. You can still get a lot of work done right out of the box, though. You don't have objects in C, but you can implement one. You can even get a little more advanced, and use more structures and function pointers to implement virtual methods. This is a simplified version, but this sort of system is the core of GObject. Of course, it's a little more advanced than this, because all those static sub_object_class things that I create don't exist (we have a system called GType). And of course GObjects have other things that modern OO environments have, like properties (which are somewhat of a mess to write right now, but people are working on it) and signals (the latter involving a whole generic "Variant" type called "GValue", and a marshaller system so that you can call function pointers with the right arguments). There's a lot of cool tricks in GObject, some of them on the line between "awesome" and "horror", and if people are interested, I'll explain this stuff.
|
# ¿ Jan 24, 2012 05:21 |
|
Look Around You posted:I've browsed through the GObject documentation a bit but still don't entirely comprehend it all. It seems like a lot of it relies on how C requires structs to be laid out in memory though. Very much so. The whole subclass casting thing relies on how things are laid out in memory. Here's a diagram: code:
If we have a SubObject *, it's saying that it's pointing to something that's 8 bytes long, and let's say, in memory, that's at 0x12340000. But since the structs are nested, there's also a valid BaseObject * at that location. Casting to a BaseObject * simply changes the pointer's size - it doesn't change the pointer's location at all. So inheritance is done by nesting structs. As we nest, the structs cannot get any smaller, and because the parent class is always the first item in the struct (at offset 0), as we nest and nest, if you unfold out the structures, the base class is always at offset 0 in memory: code:
|
# ¿ Jan 24, 2012 05:39 |
|
Look Around You posted:Yeah, multiple inheritance fucks poo poo up. I'm pretty sure GObject uses vtables though which I think most C++ compilers use for virtual functions. Sort of. It puts vfunc declarations in the class structs, and has subclasses install their own overrides in the class_init.
|
# ¿ Jan 24, 2012 06:13 |
|
The1ManMoshPit posted:Somebody's never included <Windows.h> and had to deal with nonsense error messages while trying to compile calls to std::max and std::min, or while trying to declare enum Distance { NEAR, FAR }; only to find they have been boned by all the windows #defines. Xlib has the same thing. It has #define None 0, which breaks LLVM and Qt and countless other things which do: code:
|
# ¿ Jan 29, 2012 03:58 |
|
Shady Amish Terror posted:A good example was a short in-class project where we had to write some simple code in the fewest lines possible. I beat the instructor's ~30-line example by something like six lines... by concatenating as many variable definitions as I knew how and using a loop iterator variable as data AND in a separate break condition within the loop. This was in freshman year, and pretty much set the tone of my programming since. These sorts of challenges are fun and give a clear definition of the goal to enable competitiveness. It's a great thing to clear your mind with after spending six hours staring into the abyss wondering why the hell these backtraces don't make any goddamn sense what the hell gdb what is wrong with you. Of course, the trouble happens when some confuse work with play.
|
# ¿ Jan 30, 2012 17:34 |
|
Go Twitter!
|
# ¿ Feb 1, 2012 14:57 |
|
Context: this post. Let's start with what I called "stooge maps". They wanted an ordered set of key-value pairs in JSON. How did they choose to represent it? code:
And of course, it's a pain to parse: code:
They have their own module system, of course, but it's not what you think. I have no idea why things are even divided into modules when everything still writes to the global namespace and they all cross-reference each other (even the base module code makes reference to registerModule and raiseEvent, which is in another file) We had a system where we needed fancy tooltips. I don't have CVS access any more, but the code looked like: code:
|
# ¿ Feb 4, 2012 13:09 |
|
Flobbster posted:Back in the early 90s, Amiga OS programmers called these things "tag lists"! Looks like someone was reminiscing a bit. I would have been fine if it was [ ["foo", 3], ["bar", 10] ] or even [ "foo", 3, "bar", 10 ]. I fully accept that JSON doesn't have an "ordered map" type. It's just awkward and inconvenient to represent a key/value pair by a JSON dictionary.
|
# ¿ Feb 5, 2012 17:18 |
|
Janin posted:{'foo': 3} isn't even valid JSON Oh yeah, JSON requires double quotes for strings. That's not the code's bug, it's mine.
|
# ¿ Feb 5, 2012 19:14 |
|
it is posted:I don't see what's wrong with it. it is posted:That makes 2 of us. It's fine. Are you having an identity crisis too?
|
# ¿ Feb 12, 2012 07:28 |
|
Oh, the rabbit hole goes much deeper than that. First, an old PHP feature: bare strings. In PHP, $foo = hello; is equivalent to $foo = "hello";, even though this triggers a warning in newer versions of PHP. $foo is really shorthand for ${foo}, which is really shorthand for ${"foo"}. The thing inside the braces can be any arbitrary PHP expression, so $$foo is shorthand for ${${"foo"}}. You can even do this: php:<?php $wow_php_is_dumb = "what did you expect?"; $language = "php"; echo ${wow_ . $language . _is_dumb}; You can do: php:<?php $wow_php_is_dumb_times_100 = "are you not getting it yet?"; $language = "php"; echo ${wow_ . $language . _is_dumb_times_ (10*10)}; Now, remember.... any PHP expression. Go ahead and digest this. I'll wait.
|
# ¿ Feb 14, 2012 03:34 |
|
Otto Skorzeny posted:Nope C only goes fast because compilers are allowed to write code that doesn't do what you wanted.
|
# ¿ Feb 19, 2012 18:06 |
|
darthbob88 posted:It would combine all the wisdom of Stack Overflow with the democracy of Reddit, in a final product that would, he assures me, make us zillions of dollars if I just do the backend work for him. Ah yes, zillions of dollars by basing your business model around sites that have had lots of trouble finding a viable monetization strategy. runupon cracker posted:
This is ActionScript 3? If they profiled this, this could result in a big speedup during a tight loop. Adobe's ASC compiler is terrible, and this.y compiles to: code:
Wheras var y:Number = this.y; will only do the hashmap lookup and getter once. It looks like: code:
For more evidence of Adobe's inability to write a decent compiler, have a puzzle: obj[prop] += 5; naively desugars to obj[prop] = obj[prop] + 5; (where obj and prop are arbitrary expressions). Guess why this is semantically incorrect and slow, kids!
|
# ¿ Feb 21, 2012 04:08 |
|
ToxicFrog posted:What you seem to be implying is that both obj and prop will get evaluated twice, complete with any side effects, and with the added bonus that either or both could have different values on the left and right hand sides as a result of said side effects. Yep. That's exactly it. pre:$ cat asctest.as var a = [0, 1]; var i = 0; a[(i++)] += 1; print("a is ", a); print("i is ", i); $ ./avmshell_64 asctest.abc a is 2,1 i is 2 $ fusion-swfdump asctest.abc | gist https://gist.github.com/1875229 Aleksei Vasiliev posted:That's giving Adobe a lot of credit. If you're curious about the history, the compiler was contracted to Jeff Dyer of the Mountain View Compiler Company by Macromedia. Eventually he dropped his compiler company and went full-time at Macromedia, and even served on TC-39, the ECMA standards commitee that standardizes ECMAScript. He left Adobe a little while ago, and is now doing his own thing called "Art Compiler": Useless Web Page Not so useless, if outdated, web page GitHub page His explanation when I asked him about it at a year ago
|
# ¿ Feb 21, 2012 09:58 |
|
Jabor posted:Man, changing the indentation of code really screws up git diffs. You can use git diff -w to ignore whitespace. Thankfully, GitHub exposes this feature too: add ?w=1 to the end of URLs, like so: https://github.com/php/php-src/commit/0accb4b0094b8fdda905e0a374843f0c775f4537?w=1
|
# ¿ Feb 21, 2012 21:20 |
|
They do know that power is not ^, right? EDIT: also, please tell me that you replaced it with return (2 << writelength_upper) - 1;. Suspicious Dish fucked around with this message at 23:25 on Feb 24, 2012 |
# ¿ Feb 24, 2012 23:23 |
|
I wonder how many GPL violations there are here...
|
# ¿ Mar 2, 2012 04:27 |
|
I don't understand how register_globals is a security bug at all. It's a terrible idea, sure, but not a security risk. The biggest argument that I've heard is that apparently arguments from $_GET get filled in before arguments from $_POST, so the user can add &admin=1 to the query string to get admin privileges or something. Do people really expect valid and correct information in $_POST or $_COOKIE or any of the other globals? Of course $_POST['admin'] is much more secure!
|
# ¿ Mar 5, 2012 07:05 |
|
|
# ¿ Apr 19, 2024 23:52 |
|
Wouldn't that already cause an "unset variable" error in PHP? Or do people really just Google for "php unset variable" and go "oh OK disable_errors(); should fix it".
|
# ¿ Mar 5, 2012 07:13 |