Coding: Fleeting Thoughts

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

Moderators: phlip, Moderators General, Prelates

User avatar
Diadem
Posts: 5654
Joined: Wed Jun 11, 2008 11:03 am UTC
Location: The Netherlands

Re: Coding: Fleeting Thoughts

Postby Diadem » Wed Aug 19, 2015 8:17 am UTC

Ok this week I was working implementing a new feature, when I noticed that part of the code I was working with was rather badly written. After some quick refactoring I turned three confusing functions into one clear one, with better memory management to boot. There were also some hardcoded constants in there, which I decided not to touch. Then during review, my colleague, who had written the original code, made a huge deal of these hardcoded constants, saying I really should do something about them.

So my question is, is it crazy that this pissed me off? I mean he writes bad code, I fix it while working on a different issue, and he complains I didn't fix it enough. He's right of course that having hardcoded constants is ugly, but I don't think I should be required to fix every single defect in a piece of code just because I fixed one.

Advice please.
It's one of those irregular verbs, isn't it? I have an independent mind, you are an eccentric, he is round the twist
- Bernard Woolley in Yes, Prime Minister

User avatar
Xenomortis
Not actually a special flower.
Posts: 1423
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Wed Aug 19, 2015 8:56 am UTC

No good deed goes unpunished.
I don't really have any advice for you, I guess it depends on your reasons for leaving them untouched and at what level the review is done (we have them at the commit level, which I'm not convinced is a terrific idea).

Edit:
Checked Exceptions:
A mechanism to turn a small commit into a massive one. Or at least the addition of a thousand instances of exception type erasure.
Image

User avatar
Yakk
Poster with most posts but no title.
Posts: 11088
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Aug 19, 2015 2:00 pm UTC

Everything that checks exceptions should include the type "oh_I_give_up".
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

Dr. Willpower
Posts: 197
Joined: Wed May 28, 2008 3:55 pm UTC

Re: Coding: Fleeting Thoughts

Postby Dr. Willpower » Wed Aug 19, 2015 4:34 pm UTC

Yakk wrote:Everything that checks exceptions should include the type "oh_I_give_up".


I have been known to do this in production code:

Code: Select all

if(first_possible_outcome){
    //...
} else if (second){
    //...
} else if (last_possible_outcome){
    //...
} else {
    //Shouldn't be possible~
    printf("Something terrible has happened D:");
    //...
}
Image
Hat me, bro

Breakfast
Posts: 117
Joined: Tue Jun 16, 2009 7:34 pm UTC
Location: Coming to a table near you

Re: Coding: Fleeting Thoughts

Postby Breakfast » Wed Aug 19, 2015 5:50 pm UTC

Diadem wrote:Ok this week I was working implementing a new feature, when I noticed that part of the code I was working with was rather badly written. After some quick refactoring I turned three confusing functions into one clear one, with better memory management to boot. There were also some hardcoded constants in there, which I decided not to touch. Then during review, my colleague, who had written the original code, made a huge deal of these hardcoded constants, saying I really should do something about them.

So my question is, is it crazy that this pissed me off? I mean he writes bad code, I fix it while working on a different issue, and he complains I didn't fix it enough. He's right of course that having hardcoded constants is ugly, but I don't think I should be required to fix every single defect in a piece of code just because I fixed one.

Advice please.


It's entirely reasonable to be pissed. Depending on what his relation to you is though it might be unprofessional to be. Personally, I'd probably raise the issue with a manager or lead if it happened more than once. If your a manager or lead though, it'd be part of the job to deal with that kind of thing. If he's the manager or lead... well that would suck.

User avatar
phlip
Restorer of Worlds
Posts: 7556
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Thu Aug 20, 2015 2:04 am UTC

Having been in something resembling that situation from both sides...

My first advice would be to quickly reread to confirm their tone... it'd be pretty easy for a misunderstanding to turn "well, if you're in there anyway, you may as well fix all of it" into something accusatory, or them trying to pin the blame/responsibility for fixing it onto you.

If they are, in fact, trying to play the politics or the blame game, I'd be very wary of joining them in kind... sending some sort of response trying to pin the blame back on them as the original author, while cathartic, will probably only escalate things. By all means, be pissed, come here to vent, whatever you need to do... but when you go back to them try to be calm and level about it. Don't let them pin the responsibility on you, but try to keep the discussion at something like "these hardcoded constants have been in there for a while... I don't think they should block this refactor from going in, which I believe is a major improvement. If the hardcoded constants are that big a concern for you, then you should probably raise it in whatever bug tracking system your company uses. But I feel that it's a separate issue from this change."

That would be my advice, anyway, for what it's worth.

But yeah, agreed with the above that if this is a recurring event then you have a problem. People pulling that sort of office politics bullshit on the regular basically never ends well. Ideally you'd be able to quietly talk to management, and they'd get involved to smooth it out before it gets out of hand. But I can't offer much advice on that front... certainly nothing that would be more useful than a Google search for "how to deal with office politicians".

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Diadem
Posts: 5654
Joined: Wed Jun 11, 2008 11:03 am UTC
Location: The Netherlands

Re: Coding: Fleeting Thoughts

Postby Diadem » Thu Aug 20, 2015 11:15 am UTC

Thanks for the advice! Nice to hear I'm not crazy :)

I think I'm professional enough to not let my irritation show (I hope! One can over course never be completely certain about one's subconscious body language). But the internet can be a good place to vent, or ask for advice.

I'm working in a scrum team of seven people. Officially the seven of us are all equally responsible for everything, and we do all do a little bit of everything. But this particular feature it's mostly the two of us. I've actually been on this team longer, but he has more programming experience in general, and he is a employee while I'm a consultant. Development of this feature was actually started by a third person, who recently left. I guess this left a bit of a power vacuum as to who's the alpha dog now.
It's one of those irregular verbs, isn't it? I have an independent mind, you are an eccentric, he is round the twist
- Bernard Woolley in Yes, Prime Minister

User avatar
RoadieRich
The Black Hand
Posts: 1037
Joined: Tue Feb 12, 2008 11:40 am UTC
Location: Behind you

Re: Coding: Fleeting Thoughts

Postby RoadieRich » Thu Aug 20, 2015 1:58 pm UTC

Dr. Willpower wrote:
Yakk wrote:Everything that checks exceptions should include the type "oh_I_give_up".


I have been known to do this in production code:

Code: Select all

if(first_possible_outcome){
    //...
} else if (second){
    //...
} else if (last_possible_outcome){
    //...
} else {
    //Shouldn't be possible~
    printf("Something terrible has happened D:");
    //...
}


Shouldn't that be

Code: Select all

} else {
    //Shouldn't be possible~
    throw;
    //...
}


Throw 'em all, let god sort 'em out?
73, de KE8BSL loc EN26.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1423
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Thu Aug 20, 2015 2:30 pm UTC

Code: Select all

...
} else {
  //I don't even know...
  ExitThread()
}
Image

User avatar
Yakk
Poster with most posts but no title.
Posts: 11088
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Aug 20, 2015 2:35 pm UTC

Thread?

Kill the process computer internet. It is the only way to be sure.

Have the courage of your convictions. But, first, assert.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Flumble
Yes Man
Posts: 2075
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Thu Aug 20, 2015 2:39 pm UTC

Shutting down the internet seems plausible. However, if the program is running at the customer's location, you should purge the disk, including boot sectors, to be sure the error doesn't happen again.

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3060
Joined: Sat May 09, 2009 11:55 pm UTC

Re: Coding: Fleeting Thoughts

Postby Qaanol » Thu Aug 20, 2015 2:53 pm UTC

Code: Select all

...
} else {
  // Because why not
  while(1) {
    fork()
    ping(127.0.0.1)
  }
}
wee free kings

User avatar
WanderingLinguist
Posts: 237
Joined: Tue May 22, 2012 5:14 pm UTC
Location: Seoul
Contact:

Re: Coding: Fleeting Thoughts

Postby WanderingLinguist » Fri Aug 21, 2015 12:21 am UTC

On a similar note, yesterday while trying to track down a crash in an app I work on, I ended up digging around in the Android source code and found this:

Code: Select all

// TODO clean exit
throw new RuntimeException("Need group");

Dr. Willpower
Posts: 197
Joined: Wed May 28, 2008 3:55 pm UTC

Re: Coding: Fleeting Thoughts

Postby Dr. Willpower » Fri Aug 21, 2015 4:00 pm UTC

RoadieRich wrote:
Dr. Willpower wrote:
Yakk wrote:Everything that checks exceptions should include the type "oh_I_give_up".


I have been known to do this in production code:

Code: Select all

if(first_possible_outcome){
    //...
} else if (second){
    //...
} else if (last_possible_outcome){
    //...
} else {
    //Shouldn't be possible~
    printf("Something terrible has happened D:");
    //...
}


Shouldn't that be

Code: Select all

} else {
    //Shouldn't be possible~
    throw;
    //...
}


Throw 'em all, let god sort 'em out?


I typically only do it when it's really impossible, like boolean being neither true or false. Or an int being neither greater, equal to, or less than 0.
Noting this down for next time!
Image
Hat me, bro

User avatar
Flumble
Yes Man
Posts: 2075
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Fri Aug 21, 2015 8:26 pm UTC

In most (imperative) languages can change the state of variables within the expression, so your boolean must be either false or true at any time, but it can switch between different ifs. This, of course and inevitably, means you need an else-die clause in every non-trivial if statement. :P

User avatar
phlip
Restorer of Worlds
Posts: 7556
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Sat Aug 22, 2015 4:22 pm UTC

Honestly, I'd probably write it as something like:

Code: Select all

if (first_possible_outcome){
  //...
} else if (second){
  //...
} else {
  assert(last_possible_outcome);
  //...
}
Still readably documents what the third case is for, still does runtime checks, but disappears in the release build. Or, if it's something that mathematically must be true, a comment probably suffices:

Code: Select all

if (x < 0) {
  // ...
} else if (x == 0) {
 // ...
} else { // x > 0
  // ...
}
(and even then, only if the previous blocks are long enough that the reminder is necessary)

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
phlip
Restorer of Worlds
Posts: 7556
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Thu Aug 27, 2015 2:33 pm UTC

So, a question for the seasoned profeCSSionals out there... I have this, a minimal test case heavily trimmed from a bug I'm looking into at work:

Code: Select all

<!DOCTYPE html>
<title>Overflow test</title>
<style>
.a {
  overflow: hidden;
  text-overflow: ellipsis;
}
.b {
  position: absolute;
}
.c {
  display: inline-block;
  margin-left: 50px;
  width: 100%;
}
</style>
<div class="a">
  <div class="b"></div>
  <div class="c">
    <input type="text">
    Also some words
  </div>
</div>
Open that in Chrome, or IE, you get a text box with some words after it. But open it in Firefox, and you just get an ellipsis. Except the text box is still there - mouse over where it should be and you get the text-edit cursor, and click and it'll focus the text box, which will suddenly appear again, as will the extra words after it, but once the text box loses focus it disappears again.

I... don't really know what's happening. My blind guess is that since div.c has 100% width and a margin, it's hanging outside of div.a, so maybe it wants to hide it as overflow, and since it's an inline block it's hiding the whole thing? Except that doesn't explain why it reappears when you click where the text box should be. And it doesn't explain why it only happens if the position:absolute div is there (if you remove that, it doesn't happen). Except that if you load the page with the absolute-positioned div there, and then remove it with the inspector or JS or something, that doesn't fix it. And it doesn't explain why it's only happening in Firefox.

I don't know my way around this particular codebase yet, so I'm hesitant to make sweeping changes to the CSS (which to be honest seems super overcomplicated in a lot of places) but if I knew what was going on I'd be able to kick the bug back to the team that actually works on this project with some suggestions...

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
jaap
Posts: 2085
Joined: Fri Jul 06, 2007 7:06 am UTC
Contact:

Re: Coding: Fleeting Thoughts

Postby jaap » Thu Aug 27, 2015 3:29 pm UTC

phlip wrote:Open that in Chrome, or IE, you get a text box with some words after it. But open it in Firefox, and you just get an ellipsis. Except the text box is still there - mouse over where it should be and you get the text-edit cursor, and click and it'll focus the text box, which will suddenly appear again, as will the extra words after it, but once the text box loses focus it disappears again.

Very odd. I have no clue either (but then I'm not great at CSS), but it is interesting that the effect does not happen if the b div is located elsewhere within the a div. In fact, even just putting a &nbsp; [Edit: or zero-width space &#8203;] before the b div will stop this behaviour. It does seem that the check for overflow is confused by having the contents starting with an absolutely positioned element.

User avatar
phlip
Restorer of Worlds
Posts: 7556
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Fri Aug 28, 2015 1:09 am UTC

Huh, that's even weirder.

But it does suggest the easy workaround of swapping b and c in the tree... since b is absolutely positioned that doesn't affect the layout at all, and now it works...

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Xanthir
My HERO!!!
Posts: 5330
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Fri Aug 28, 2015 8:26 am UTC

phlip wrote:I... don't really know what's happening. My blind guess is that since div.c has 100% width and a margin, it's hanging outside of div.a, so maybe it wants to hide it as overflow, and since it's an inline block it's hiding the whole thing?

Nope, div.a is acting normally - it's tall enough to contain its text/input children, and it stretches to fill the window. div.c *does* overflow slightly, but that just means that that its right end is clipped a bit.

This is just a painting bug on Firefox's part. There's nothing for it but to figure out how to hack around it, as jaap provided.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Flumble
Yes Man
Posts: 2075
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Fri Aug 28, 2015 9:39 am UTC

Xanthir wrote:This is just a painting bug on Firefox's part. There's nothing for it but to figure out how to hack around it, as jaap provided.

...and reporting the bug hoping that you don't have to use that work-around in the future. :)

User avatar
Diadem
Posts: 5654
Joined: Wed Jun 11, 2008 11:03 am UTC
Location: The Netherlands

Re: Coding: Fleeting Thoughts

Postby Diadem » Tue Sep 01, 2015 2:16 pm UTC

My day today:
(spoilered for size)
Spoiler:
Image
It's one of those irregular verbs, isn't it? I have an independent mind, you are an eccentric, he is round the twist
- Bernard Woolley in Yes, Prime Minister

DaveInsurgent
Posts: 207
Joined: Thu May 19, 2011 4:28 pm UTC
Location: Waterloo, Ontario

Re: Coding: Fleeting Thoughts

Postby DaveInsurgent » Tue Sep 01, 2015 5:16 pm UTC

Diadem wrote:Thanks for the advice! Nice to hear I'm not crazy :)

I think I'm professional enough to not let my irritation show (I hope! One can over course never be completely certain about one's subconscious body language). But the internet can be a good place to vent, or ask for advice.

I'm working in a scrum team of seven people. Officially the seven of us are all equally responsible for everything, and we do all do a little bit of everything. But this particular feature it's mostly the two of us. I've actually been on this team longer, but he has more programming experience in general, and he is a employee while I'm a consultant. Development of this feature was actually started by a third person, who recently left. I guess this left a bit of a power vacuum as to who's the alpha dog now.


I don't know if this helps but working in a similar situation I brought in the fairly accepted notion that something is "existing baggage", and so I'd either reply-if-caught or preemptively comment on my own PR saying like, I know this sucks but it's existing baggage and I've tried to make it "better" not "best".

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Wed Sep 02, 2015 3:54 pm UTC

Suppose I have three sets of strings:

Code: Select all

a) { "$22.08" "$21.92" "$18.75" }
b) { "$10.08" "$2.56" "$10875.21" }
c) { "Friday, February 27th" "Monday, January 8th" "Wednesday, September 23rd" }


If you ask a human being, they will probably tell you that it's pretty likely that a) and b) represent data from the same data set, and pretty unlikely that a) and c) do.

Is there a word for the problem of training computers to make that sort of judgement? It seems like it's related to record linkage or schema matching, but it's not quite the same thing.
He/Him/His/Alex
God damn these electric sex pants!

User avatar
Flumble
Yes Man
Posts: 2075
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Wed Sep 02, 2015 6:17 pm UTC

If you know the types of data beforehand, it's a simple classification problem. But since you're asking the question, I bet you don't have the classes available beforehand.

I believe hope cluster analysis is the thing you're looking for. Well, in case you come up with a few useful dimensions to your data.

Other methods include neural networks and genetic algorithms (types of machine learning), that try to match the data from one list as best as they can and not match random garbage with iterative training, so they essentially become the classifiers. Then you can run another list through it and you get the likelihood that the data types are the same.


Note: all buzzwor- I mean useful keywords you can use for searches are emphesized.
Note: I don't have any experience in this field, so my advice can be completely misguiding you.

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Wed Sep 02, 2015 9:54 pm UTC

Flumble wrote:If you know the types of data beforehand, it's a simple classification problem. But since you're asking the question, I bet you don't have the classes available beforehand.

I believe hope cluster analysis is the thing you're looking for. Well, in case you come up with a few useful dimensions to your data.

Other methods include neural networks and genetic algorithms (types of machine learning), that try to match the data from one list as best as they can and not match random garbage with iterative training, so they essentially become the classifiers. Then you can run another list through it and you get the likelihood that the data types are the same.


Note: all buzzwor- I mean useful keywords you can use for searches are emphesized.
Note: I don't have any experience in this field, so my advice can be completely misguiding you.
Thanks, but those sound more like methods that one might use to solve the problem than the name of the problem itself. I expect most solutions would use either some kind of machine-learny cluster analysis (although there might be simple rules-based solutions as well).
He/Him/His/Alex
God damn these electric sex pants!

User avatar
Flumble
Yes Man
Posts: 2075
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Wed Sep 02, 2015 11:41 pm UTC

My bad, I shifted from looking for the problem name to looking for answers to the problem while writing my post. :roll:
So yeah, classification/pattern recognition/clustering problem is as specific as I can think of.

Anyway, in the example you provided: are the rows tuples or sets? (I get the impression from the articles you linked that each row is one entry, but I get the impression that each row is a set of entries because they're all the same type.)

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Wed Sep 02, 2015 11:50 pm UTC

Flumble wrote:Anyway, in the example you provided: are the rows tuples or sets? (I get the impression from the articles you linked that each row is one entry, but I get the impression that each row is a set of entries because they're all the same type.)

Sets. The more specific problem I'm looking at is: you have two spreadsheets with data that is semantically the same but is labeled and formatted differently, and you want to figure out which columns from spreadsheet a) match which columns in spreadsheet b). The data points are samples from the columns.

So the similar formatting might count as evidence that a) and b) are the same column, even if we don't know the types up front.
He/Him/His/Alex
God damn these electric sex pants!

User avatar
Jplus
Posts: 1711
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Thu Sep 03, 2015 6:25 am UTC

Ah, the importing data from human-entered Excell files problem. Poor you.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

User avatar
jestingrabbit
Factoids are just Datas that haven't grown up yet
Posts: 5967
Joined: Tue Nov 28, 2006 9:50 pm UTC
Location: Sydney

Re: Coding: Fleeting Thoughts

Postby jestingrabbit » Thu Sep 03, 2015 9:05 am UTC

Sounds like the classification problem.

http://c2.com/cgi/wiki?ClassificationProblem

Good luck.
ameretrifle wrote:Magic space feudalism is therefore a viable idea.

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Thu Sep 03, 2015 2:56 pm UTC

Jplus wrote:Ah, the importing data from human-entered Excell files problem. Poor you.

Fortunately for me, I don't actually have to do this. I just have to maintain the software.
He/Him/His/Alex
God damn these electric sex pants!

User avatar
Flumble
Yes Man
Posts: 2075
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Thu Sep 03, 2015 3:02 pm UTC

ahammel wrote:
Jplus wrote:Ah, the importing data from human-entered Excell files problem. Poor you.

Fortunately for me, I don't actually have to do this. I just have to maintain the software.

You're saying "fortunately", but that might be your Stockholm's speaking. :P

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Fri Sep 04, 2015 11:54 pm UTC

Flumble wrote:
ahammel wrote:
Jplus wrote:Ah, the importing data from human-entered Excell files problem. Poor you.

Fortunately for me, I don't actually have to do this. I just have to maintain the software.

You're saying "fortunately", but that might be your Stockholm's speaking. :P

Could be, could be.

Unrelated, but if you need a Slack bot to keep track of Elo ratings, I got you covered.
He/Him/His/Alex
God damn these electric sex pants!

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

Re: Coding: Fleeting Thoughts

Postby Ubik » Sun Sep 06, 2015 7:45 pm UTC

In OpenGL, if you want to update buffer contents, you first bind the buffer and then issue BufferData or BufferSubData (or MapBuffer) command. Except that when the buffer is an index buffer. In that case you bind the vertex array object the index buffer is attached to.

Of course, if you can limit yourself to OpenGL 4.5 or are brave enough to require the direct state access extension, you can just update the data without ever binding anything. I'd just like to use pure 3.3 as long as that is the best my graphics card can do with the current drivers.

Edit: Maybe I'll just make the vertex array object act as if it is the buffer. And then, because a VAO might not actually have an index buffer attached to it, it is a buffer only optionally. Then the GL wrapper just has to handle all buffers like they were buffers only optionally. Meh, maybe that's not really a problem.

Edit 2: Oh now I think I got it! I'll just make it so that if there's no index buffer attached to the VAO, the buffer operations simply cause an error. Which seems like an obvious way thing to happen when doing buffer operations with a non-buffer thing. Technically that is almost the same as having the "bufferness" be optional (this is Rust, so it's Option vs. Result), but conceptually it feels a bit nicer, because the dirty detail is handled internally by the object, instead of changing an interface just because of a single case.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6300
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Wed Sep 09, 2015 8:06 pm UTC

My two biggest pet peeves:

1) Code that is commented out instead of deleted
2) Database queries that use select distinct when they include the primary keys of all tables in the join

They are so prevalent here.
Summum ius, summa iniuria.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11088
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Sep 10, 2015 6:40 pm UTC

So `int` and `char*` and `int*` and `std::vector<T>::iterator` all model a concept.

It supports `T==T`, `T!=T`, `T+=/-= integral_type`, `T=T+/-integral_type`, `T=integral_type+T`, `T{}`, `T=T`, `T{T}`, `integral_type = T-T` and `T<T` (etc) to a limited extent. (Plus reasonable axioms for most of these operations, like `T_y = T_x + (T_y-T_x)`)

It does not support `T+T`, `T*integral_type`, `T/integral_type`. So it isn't a vector space.

Is there a name for the common abstraction? Affine space over the integers with a null and a partial order maybe?
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Xanthir
My HERO!!!
Posts: 5330
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Fri Sep 11, 2015 1:21 am UTC

Yeah, if you assume "integral_type" is just a shorthand way of writing the type with the obvious constructor, then it's an affine space variant.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

operator[]
Posts: 155
Joined: Mon May 18, 2009 6:11 pm UTC
Location: Stockholm, Sweden

Re: Coding: Fleeting Thoughts

Postby operator[] » Fri Sep 11, 2015 7:28 am UTC

A disjoint union of ordered torsors, perhaps?

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? » Fri Sep 11, 2015 10:15 am UTC

I guess you could argue you're defining a group homomorphism between your integral_type (let's rename that s) and your pointer/iterator/whatever T(s).

There's an inverse transform T-1(T(s)) = T(s) - T(0) = s, and there's an operator can be defined so that T(s + s') = T(s) x T(s'), and there's a unity element in s so that T(s + u) = T(s), and in T so that T-1(Tu) = u.

Disclaimer: My abstract algebra is rather rusty.

--edit--

Actually, is T(s) a group though? It has an identity morphism, endomorphisms (++iter) that are invertible (--iter) and associative, and it's closed within these operations. So s->T(s) is a homomorphism between an abelian group and a category or a monoid or some such?

Like I said, rusty :-/
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11088
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Fri Sep 11, 2015 12:46 pm UTC

operator[] wrote:A disjoint union of ordered torsors, perhaps?

That looks like it.

There is a bit more structure -- the (limited?) ordering structure. So both integral types and pointers and (random access) iterators are ordered Z-torsors.

Not sure where you got disjoint union. Because pointers/iterators are only valid within their domain?
SecondTalon wrote:pointer/iterator/whatever T(s).

Pointer/interator etc aren't groups. There is no TxT->T operator for them, let alone an intertible one.
Xanthir wrote:Yeah, if you assume "integral_type" is just a shorthand way of writing the type with the obvious constructor, then it's an affine space variant.

Well, it is something that behaves integer-like. As we are talking a mathematical abstraction for now, I'd guess Z is good enough. (ptrdiff_t more likely in practice, which isn't quite Z)

It isn't an affine space, because we don't have a field. It looks like a torsor is to a group as an affine space is to a vector field. The group in question being Z+.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 7 guests