Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Sat Mar 20, 2010 12:24 am UTC

hotaru wrote:
itaibn wrote:I was this close to finding the Ultimate Question. :cry:

Code: Select all

>>> 0x2b or not 0x2b
43

just add a double negative at the beginning...

Code: Select all

>>> ~-0x2b or not 0x2b
42
Not a very constructive suggestion, now is it?
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

Posi
Posts: 111
Joined: Mon Jul 16, 2007 6:08 am UTC

Re: Coding: Fleeting Thoughts

Postby Posi » Sat Mar 20, 2010 9:28 pm UTC

itaibn wrote:I was this close to finding the Ultimate Question. :cry:

Code: Select all

>>> 0x2b or not 0x2b
43

Wait.

I thought A or not A was always 1?
Edit: or in this case, FF.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Sat Mar 20, 2010 9:34 pm UTC

hotaru wrote:just add a double negative at the beginning...

Code: Select all

>>> ~-0x2b or not 0x2b
42

That is the question.

Wait, that kind of makes sense.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
lulzfish
Posts: 1214
Joined: Tue Dec 16, 2008 8:17 am UTC

Re: Coding: Fleeting Thoughts

Postby lulzfish » Sat Mar 20, 2010 9:53 pm UTC

Posi wrote:
itaibn wrote:I was this close to finding the Ultimate Question. :cry:

Code: Select all

>>> 0x2b or not 0x2b
43

Wait.

I thought A or not A was always 1?
Edit: or in this case, FF.

0x2b => 0010 1011
not 0x2b => 1101 0100

0x2b or not 0x2b => 1111 1111
Yeah, and FF is like... 255, not 42.
What kind of math are we using?

User avatar
e^iπ+1=0
Much, much better than Gooder
Posts: 2065
Joined: Sun Feb 15, 2009 9:41 am UTC
Location: Lancaster

Re: Coding: Fleeting Thoughts

Postby e^iπ+1=0 » Sat Mar 20, 2010 9:58 pm UTC

The kind that python uses.

Code: Select all

>>> 0x2b
43
>>> not 0x2b
False
>>> 0x2b or not 0x2b
43
poxic wrote:You, sir, have heroic hair.
poxic wrote:I note that the hair is not slowing down. It appears to have progressed from heroic to rocking.

(Avatar by Sungura)

User avatar
chridd
Has a vermicelli title
Posts: 846
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Sat Mar 20, 2010 10:04 pm UTC

lulzfish wrote:What kind of math are we using?
The kind where "or" evaluates to its first argument if the its first argument is considered "true" (when converted to a Boolean), and its second argument otherwise.
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she · Forum game scores
mittfh wrote:I wish this post was very quotable...

User avatar
Pesto
Posts: 737
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Re: Coding: Fleeting Thoughts

Postby Pesto » Sat Mar 20, 2010 11:06 pm UTC

e^iπ+1=0 wrote:The kind that python uses.

Code: Select all

>>> 0x2b
43
>>> not 0x2b
False
>>> 0x2b or not 0x2b
43

Should work in C, too.

0x2b | !0x2b

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Sat Mar 20, 2010 11:43 pm UTC

In C++ it'll only work with xor because or returns either 0 or 1.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Mar 20, 2010 11:46 pm UTC

TheChewanater wrote:In C++ it'll only work with xor because or returns either 0 or 1.


Not if you use bitwise or (like Pesto is using).
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
NieXS
Why's the rum gone?
Posts: 286
Joined: Wed Mar 12, 2008 3:10 am UTC
Location: Brazil

Re: Coding: Fleeting Thoughts

Postby NieXS » Sat Mar 20, 2010 11:49 pm UTC

FT: I want Ruby 1.8's strings back.
she/her


User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sun Mar 21, 2010 12:00 am UTC

FT: We have strings. What do you do with a string? You pull it. Why is there no string-operation suitable to occupy that name?
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Sun Mar 21, 2010 12:00 am UTC

You, sir, name? wrote:
TheChewanater wrote:In C++ it'll only work with xor because or returns either 0 or 1.


Not if you use bitwise or (like Pesto is using).


I meant the or and xor operators, which are logical operators and not bitwise.

Also, this works. It even has a question mark.

Code: Select all

#include <iostream>

#define answer_to_everything = //Equals what?

int that = '?';

int
main ()
{
   //The answer is 42, but what is the question?
   int the answer_to_everything 42, question = '?';

   std::cout << (

      0x2b or not 0x2b? that =  the : question

   ) << std::endl;
}
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sun Mar 21, 2010 12:12 am UTC

TheChewanater wrote:
You, sir, name? wrote:
TheChewanater wrote:In C++ it'll only work with xor because or returns either 0 or 1.


Not if you use bitwise or (like Pesto is using).


I meant the or and xor operators, which are logical operators and not bitwise.


You can always build a logical xor out of bitwise xor and the tautology operator "!!".

if( (!!a) ^ (!!b) ) ...
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Sun Mar 21, 2010 12:17 am UTC

You, sir, name? wrote:You can always build a logical xor out of bitwise xor and the tautology operator "!!".

if( (!!a) ^ (!!b) ) ...

I meant, literally, and, or, xor, etc, that exist in C++.

Code: Select all

std::cout << true xor false;
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sun Mar 21, 2010 12:27 am UTC

TheChewanater wrote:
You, sir, name? wrote:You can always build a logical xor out of bitwise xor and the tautology operator "!!".

if( (!!a) ^ (!!b) ) ...

I meant, literally, and, or, xor, etc, that exist in C++.

Code: Select all

std::cout << true xor false;


Wikipedia says
"C++ defines[1] keywords to act as aliases for a number of symbols that function as operators: and (&&), bitand (&), and_eq (&=), or (||), bitor (|), or_eq (|=), xor (^), xor_eq (^=), not (!), not_eq (!=), compl (~). These are parsed exactly like their symbolic equivalents, and can be used in place of the symbol they replace. It is the punctuation that is aliased, not the operators. For example, bitand can replace both the bitwise AND operator and the address-of operator."
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Sun Mar 21, 2010 12:44 am UTC

You, sir, name? wrote:Wikipedia says
"C++ defines[1] keywords to act as aliases for a number of symbols that function as operators: and (&&), bitand (&), and_eq (&=), or (||), bitor (|), or_eq (|=), xor (^), xor_eq (^=), not (!), not_eq (!=), compl (~). These are parsed exactly like their symbolic equivalents, and can be used in place of the symbol they replace. It is the punctuation that is aliased, not the operators. For example, bitand can replace both the bitwise AND operator and the address-of operator."


Yes, "or" in C++ is || (logical), while xor is "^" (bitwise).

Code: Select all

std::cout << (0x2b or not 0x2b);

is false in C++ (which is, of course, 0).

Code: Select all

std::cout << (0x2b xor not 0x2b);

is 0x2b (which is, as we all know, 43).
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Sun Mar 21, 2010 12:50 am UTC

NieXS wrote:FT: I want Ruby 1.8's strings back.
What in particular about them?

User avatar
NieXS
Why's the rum gone?
Posts: 286
Joined: Wed Mar 12, 2008 3:10 am UTC
Location: Brazil

Re: Coding: Fleeting Thoughts

Postby NieXS » Sun Mar 21, 2010 1:41 am UTC

The simple fact that they ignore character encodings, and are pretty much byte arrays.
she/her


User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Sun Mar 21, 2010 10:50 am UTC

Why not use, you know, byte arrays instead of strings for that?
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Wed Mar 24, 2010 1:09 am UTC

We already know haskell makes you a worse programmer but today I learned that working with Java is fun.

Something was not working. Some value did not change as we wanted it to, and the lack of change happened somewhere in a chain of apps sending stuff to eachother via JMS. Well, when I say it happened somewhere, it actually happened in many places, but mostly it was supposed to not change. This made locating it a bit hard, as you might imagine. Well, when I say hard I mean time-consuming. Deploying and undeploying modules, inserting extra log statements, rebuilding and running things in debug on an app-server is not the prefered way of getting rapid feedback.

Anyway, back to the bug, the value was changed somewhere and then changed back somewhere else by something else that shouldn't be touching that. Mutable state had messed up, and now things were fucked up. After hours of poking at the code, killing the appserver every time our poor machines hit their 4gb memory limit and blaming eachothers' apps we had closed in on the location. It wasn't entirely known yet, and it led to a bit of a discussion, since right before we sent the message the value was right, but right after it was received on the other end it was wrong. Some of us wanted to blame JMS for having some obscure bug (it has several others, which had hampered us in debugging. The workaround was the digital equivalent of giving the app server a kick on the shin each time it acted up), but someone had written a test-app where the value did change as it was supposed to. After a bit more debugging, restarting and cups of coffee we had narrowed it down to the following line:

Code: Select all

dst.setFoo(src.getFoo());

Ah, so some getter or setter must be fucked up then. However:

Code: Select all

public void setFoo(Foo foo){this.foo = foo;}
public Foo getFoo(){return foo;}

The following conversation went something like:

"Uh... lolwut?"
"Wtf?!"
"Whaaaat?! Whaaaat?! Whaaaat?!"
"FFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUUU......"
".... I'll put on more coffee."

The bravest of us embarked on yet another debugging session. As you might expect at this point, the bug was very good at thwarting any attempt at being run through the debugger. Almost every time we ran it through that section of code, something different would happen. Sometimes the value apparantly wouldn't change back, sometimes it did at the previously mentioned line, sometimes it would start out with the wrong value altogether. Wasting even more time trying to get something reproducible one of us suddenly noticed that some object was of the wrong type. It wasn't the type we expected, but it had inherited from it, as per good OO practice, saving us from evil code duplication. It did however override the getFoo method. You see, Foo is really a map, and there are more maps in the outer object, and the overridden getFoo copied the entries from some other maps into the foo map, overwriting some keys that really shouldn't be overwritten.

So we've found the bug and alls well, right? Of course not. Remember how the test-app worked? Yeah, it shouldn't have. Fortunately, dangerously close to caffeine poisoning, high on sugar and halfway insane, one of the more experienced developers had a flash of brilliance and realized what the fundamental difference was: The test-app didn't fuck with the object graph. It edited the values of the values in the maps directly, while the real application was creating new objects with the new values. This meant that in the test-app it didn't matter that the map entries were overwritten, because the objects were the same anyway. Two wrongs had made a right.

Then there was fixing the bug. The same coworker who had the flash of brilliance suggested in a flash of not-really-brilliance not messing with the object graph in the real application. Another alternative was of course the quick hack to detect the value of the wrong type and somehow fix it up, but this would require a major kludge and wouldn't really fix the bug, but only mask it. The real solution was of course to not send the subtype out, but that part was in a critical core app with a somewhat long and cumbersome release cycle, and it had recently gotten an upgrade involving amongst other things multithreading a previously single-threaded part that wasn't properly combat tested yet, so getting the bugfix out was going to take a while. Knowing from experience that any serious bugs will wait until they're in production to manifest anyway we went for the last option. This involved sacraficing the duplication-saving inheritance of the until-then subclass, replacing it with ... a 3 line static method in some random utility class (probably named ObjectManagerDataHandler), last I checked.

Oh, and this was a "serious" bug, so of course it was in production. This meant databases full of blobs of serialized objects (for the record, I HAD NOTHING TO DO WITH THIS DESIGN DESICION! IT WAS MADE BEFORE MY TIME) that the system now wouldn't understand anymore. This again meant writing a converter, converting from the subtype to the supertype. Since encapsulation is very important, and the subtype had properly encapsulated the supertype's overridden methods, this meant some hackery was needed just to get the state out of the objects and into new ones. This is what I'm working on at the moment.

How was this fun, you ask? Well, first of all, I was pretty sure the bug wasn't mine so there was no honour at stake. I was free to enjoy the thrill of the chase and the challenge of a puzzle where the pieces were all well hidden, both at the same time. I got to demonstrate skill and knowledge, during the debugging, during the design of the fix and now during the implementation of the fix, three rather different arenas. Finally I got to laugh at the poor sods who messed up in the first place. I like to pretend it's all in good nature, but I really enjoy dragging people through the mud and kicking them when they're down, even when their mistakes are relatively minor, as they really were in this case.

And that's another fun thing. The realization that this bug had a rather simple and common two-part cause (mutable state and inheritance, both easy and common to mess up), yet managed to wreack such havoc that even state-of-the-art (or at least pretending to be) debugging tools and techniques came up short several times. Also, the fix is complicated by encapsulation, now requiring me to dig deep into the code of both the subclass and superclass mentioned to write a brittle and ugly way of fixing up the mess in production, something that in for example python would just be copying a few fields directly instead of through property accessors. As you might've guessed from the previous paragraph, I can thrive on carnage, and carnage caused by failed good intentions is all the sweeter.

All in all, it wasn't really that big of a bug either. It was elusive, sure, but the cause was eventually rather trivial, the consequences less critical and the fix easier to implement than several other bugs I've seen. Much of the cause and complications were caused by a relatively inane mistake to make, and good OO practice messed it up even further. I estimate that these three things, mutable state, inheritance and encapsulation just cost my employer somewhere between $1000 and $2000 in wages and project setback.

Note that I'm not bashing on OO here, or claiming functional programming is somehow better. Sure, Haskell doesn't have mutable state or inheritance, but that doesn't mean code written in it is free of bugs. This would never happen in Haskell, but I don't have the large-project experience to prove it, and besides, where would you get your kicks?

tl;dr: See above.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
crush pill
Posts: 31
Joined: Sat Jan 30, 2010 5:25 am UTC

Re: Coding: Fleeting Thoughts

Postby crush pill » Wed Mar 24, 2010 1:22 am UTC

yeah philip and berengal are pretty cool, like i said before, though philip is actually phlip for some reason or another, but neither are from the states, not that that matters, because programming doesn't depend on who you are, it depends on what ya know, ya know?

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Coding: Fleeting Thoughts

Postby 0xBADFEED » Wed Mar 24, 2010 3:10 pm UTC

Berengal wrote:All in all, it wasn't really that big of a bug either. It was elusive, sure, but the cause was eventually rather trivial, the consequences less critical and the fix easier to implement than several other bugs I've seen. Much of the cause and complications were caused by a relatively inane mistake to make, and good OO practice messed it up even further. I estimate that these three things, mutable state, inheritance and encapsulation just cost my employer somewhere bewteen $1000 and $2000 in wages and project setback.
Note that I'm not bashing on OO here, or claiming functional programming is somehow better. Sure, Haskell doesn't have mutable state or inheritance, but that doesn't mean code written in it is free of bugs. This would never happen in Haskell, but I don't have the large-project experience to prove it, and besides, where would you get your kicks?

It's not clear to me that this was the fault of OO or mutable state and it's not clear that any of this was "good OO practice". Specifically, it sounds like the subtype violated assumptions made about the supertype to the point that it no longer satisfied the substitution principle. In fact, that sounds like quite bad OO practice. There seems to me only one culprit here, assumptions were violated. This is equally possible to do in any other language, including Haskell by violating assumptions made about operations on typeclass instances.

Of course, maybe I'm not understanding the full scope of the bug.

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: Coding: Fleeting Thoughts

Postby rrwoods » Wed Mar 24, 2010 4:13 pm UTC

0xBADFEED wrote:the substitution principle
is the cornerstone of good OO. If you aren't substitutable for each of your superclasses then you're doing it wrong.

Unfortunately this is impossible to enforce at compile time, so this principle gets violated a lot in practice. Hence Berengal's problem.
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Wed Mar 24, 2010 9:39 pm UTC

rrwoods wrote:
0xBADFEED wrote:the substitution principle
is the cornerstone of good OO. If you aren't substitutable for each of your superclasses then you're doing it wrong.
Indeed, but that really means you have to a) decide up front where you're using the classes, or b) only add functionality, never remove or change it. The first destroys composability entirely. The second option is no better than just adding the functionality directly in the superclass, which makes inheritance rather useless. The first case is really the only case inheritance is useful, and it ultimately means that to understand a class you also need to understand everywhere it's used.

Interfaces (and type classes) are a different story, because they don't have any functionality in themselves, they only expose an interface.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Coding: Fleeting Thoughts

Postby 0xBADFEED » Thu Mar 25, 2010 1:44 pm UTC

Berengal wrote:Indeed, but that really means you have to a) decide up front where you're using the classes ... The first destroys composability entirely ... The first case is really the only case inheritance is useful, and it ultimately means that to understand a class you also need to understand everywhere it's used.

No, a class defines its assumptions and behavioral guarantees for usage. Users of the class (including extenders) must adhere to the class's assumptions and expectations. A class need not concern itself with how it is used as long as its assumptions and expectations hold. I mean if your statement were really true then things like class-based UI toolkits would be complete failures. But they're not, they're enormously successful and do a good job of solving the problem. They're very composable and extendable. In OO the mechanism of composition is object composition, not inheritance. Object composition is also the major mechanism of code reuse, not inheritance, as some might have you believe. Inheritance is primarily useful for polymorphism and only tangentially useful in composition and code reuse.
b) only add functionality, never remove or change it. ... The second option is no better than just adding the functionality directly in the superclass, which makes inheritance rather useless.

You can add, change, or remove behavior in a subclass as long as it doesn't violate assumptions or guarantees made by the supertypes whether they be explicit or implicit. And there are plenty of reasons why you might add/remove/change behavior in a subclass. If your main exposure to OO is through Java I can understand why you might have some mixed up interpretations of OO.

Also, sorry I chopped up your post so bad. I wanted to respond to the two points separately and that was the best I could do.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Thu Mar 25, 2010 7:05 pm UTC

Oh, object composition is all well and good and rational. Indeed, it's how I write most of my Java code. You don't really give a good reason for class inheritance though. Interfaces gives you polymorphism when you need it, which frankly isn't really that often. I haven't used class-based UI toolkits much, but from what I've seen it's mostly abstract classes, which to me just look like weird mixins and are just as easily done by providing a delegate object (I've often refactored abstract classes in such a way once the code demanded more flexibility), or interfaces. In fact, the newer ones seem to be more interfaces than classes, at least that you're supposed to inherit from.

Java does have a fucked up interpretation of OO, and my exposure is mainly through that language. I have played with other OO languages that are much better at it though (ruby and smalltalk), and I still think class inheritance is a bad idea. Object composition and interfaces provide the same functionality and the same expressibility (some languages, like Java, requires a boatload of extra boilerplate, but Java requires a boatload of extra boilerplate for everything, and any IDE with respect for itself will provide some way of writing it for you) and are harder to get wrong. Remove class inheritance and you won't lose anything. Remove any of the two others and you've made quite a mess of the language.

Null pointers are still worse though. One screwed us over royally today.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Coding: Fleeting Thoughts

Postby 0xBADFEED » Thu Mar 25, 2010 11:47 pm UTC

Berengal wrote:Oh, object composition is all well and good and rational. Indeed, it's how I write most of my Java code. You don't really give a good reason for class inheritance though. Interfaces gives you polymorphism when you need it, which frankly isn't really that often. I haven't used class-based UI toolkits much, but from what I've seen it's mostly abstract classes, which to me just look like weird mixins and are just as easily done by providing a delegate object (I've often refactored abstract classes in such a way once the code demanded more flexibility), or interfaces. In fact, the newer ones seem to be more interfaces than classes, at least that you're supposed to inherit from.

Java does have a ULTRAFUCKED up interpretation of OO, and my exposure is mainly through that talky...word thing. I have played with other OO talky...word things that are much better at it though (ruby and smalltalk), and I still think class inheritance is a bad idea. Object composition and interfaces provide the same functionality and the same expressibility (some talky...word things, like Java, requires a boatload of extra boilerplate, but Java requires a boatload of extra boilerplate for everything, and any IDE with respect for itself will provide some way of writing it for you) and are harder to get wrong. Remove class inheritance and you won't lose anything. Remove any of the two others and you've made quite a mess of the talky...word thing.

Basically the answer is that inheritance is a degenerate instance of mixins. If you have a language that supports mixins with interface-based polymorphism then you don't need it. However, most mainstream languages don't offer this. So what you're left with is inheritance. I still don't think this makes inheritance a "bad idea". It's not the best idea, but it was a good idea at the time and if you're using a language like C++ or Java it's basically the fastest way to share implementations between classes. You can always go back and refactor it into interfaces with object composition. But in the frequent case when you really only have a few subclasses it's more time-efficient to just inherit the implementation.

User avatar
Pesto
Posts: 737
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Re: Coding: Fleeting Thoughts

Postby Pesto » Fri Mar 26, 2010 12:37 am UTC

FT: It would save a lot of grief if UPDATE sql queries were to require a WHERE clause. If you actually want to update every row in a table, you can just say 'WHERE 1=1'.

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: Coding: Fleeting Thoughts

Postby Emu* » Fri Mar 26, 2010 12:58 am UTC

So we should force the language to require a meaningless pointless clause to protect against insufficiently awake programmers?
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

User avatar
Pesto
Posts: 737
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Re: Coding: Fleeting Thoughts

Postby Pesto » Fri Mar 26, 2010 2:24 am UTC

Emu* wrote:So we should force the talky...word thing to require a meaningless pointless clause to protect against insufficiently awake programmers?

Of all update queries ever issued that had no where clause, how many do you think were intentional, and how many do you think were unintentional?

Same question for deletes.

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Coding: Fleeting Thoughts

Postby hotaru » Fri Mar 26, 2010 3:44 am UTC

i think we should instead require people to pass a simple test to prove that they're awake before they're allowed to go mucking around in databases that contain anything of value.

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Fri Mar 26, 2010 3:52 am UTC

Better yet, just automatically prepend any manually-entered queries with "START TRANSACTION"...
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
Pesto
Posts: 737
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Re: Coding: Fleeting Thoughts

Postby Pesto » Fri Mar 26, 2010 4:44 am UTC

Okay, compromise. Make it a configurable option on the DBMS.

User avatar
'; DROP DATABASE;--
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy
Contact:

Re: Coding: Fleeting Thoughts

Postby '; DROP DATABASE;-- » Fri Mar 26, 2010 9:25 am UTC

Agree with the "UPDATE should require WHERE" thing. I wonder how many tables that's ruined? I've heard some OSes implement a similar protection that prevents "rm -rf /" (but you can still do e.g rm -rf /* if you really want), to prevent the case where a script does "rm -rf $foo/$bar" and $foo and $bar happen to not have been set. I'm not about to try it to find out for sure, though. :P

*reads page 42*
That C-embedded-in-Python thing should NOT be possible. It's witchcraft, I tells you!
b.i.o wrote:
'; DROP DATABASE;-- wrote:(yes that is old messy code being replaced with nice shiny new code.)

...I sure hope so. That's disgusting.
The program was mostly based on decompiled machine code, so it did get quite ugly at points. The process was along the lines of "decompile, re-implement, understand, re-implement nicely." It works, but you get that crap in the second step. The new code is about 8 zillion times nicer. :D

TheChewanater wrote:While writing to a textbook publisher to complain about their book on web design, I included this at the end of my citations.

Code: Select all

[[my name]]. My brain. May 1995.
<ftp://192.168.1.-1/public/>
Real geeks substitute `whoami` for their name. ;) (Nice IP though. Your brain speaks TCP/IP?)
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Fri Mar 26, 2010 7:07 pm UTC

'; DROP DATABASE;-- wrote: (Nice IP though. Your brain speaks TCP/IP?)

Sort of. It's not technically up to specs because the IP isn't from 1 to 256 (or is it 0 to 255?).
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
chridd
Has a vermicelli title
Posts: 846
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Fri Mar 26, 2010 7:19 pm UTC

TheChewanater wrote:(or is it 0 to 255?).

127.0.0.1?
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she · Forum game scores
mittfh wrote:I wish this post was very quotable...

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Fri Mar 26, 2010 7:42 pm UTC

chridd wrote:
TheChewanater wrote:(or is it 0 to 255?).

127.0.0.1?

Yeah, but that still doesn't include -1, which can't be represented in a 32 bit unsigned int.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

Ubik
Posts: 1016
Joined: Thu Oct 18, 2007 3:43 pm UTC

Re: Coding: Fleeting Thoughts

Postby Ubik » Fri Mar 26, 2010 8:19 pm UTC

Each dot-separated part of an IPv4 address fits into a byte, so it could be -1 as signed char, or 255 in the more conventional notation. At least that's how I read it.

Posi
Posts: 111
Joined: Mon Jul 16, 2007 6:08 am UTC

Re: Coding: Fleeting Thoughts

Postby Posi » Sat Mar 27, 2010 5:37 am UTC

It bugs me that this

Code: Select all

d <= q when en = '0';


and this

Code: Select all

d <= q when en = '0' else d;


are not the same thing.

OT: Do you guys ever press New Topic instead of Post Reply?

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Sat Mar 27, 2010 5:39 am UTC

Posi wrote:OT: Do you guys ever press New Topic instead of Post Reply?
No, but I did always find it strange that they put that button right there...


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 12 guests