Coding: Fleeting Thoughts

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

Moderators: phlip, Moderators General, Prelates

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

Re: Coding: Fleeting Thoughts

Postby Xanthir » Sat Jul 02, 2016 5:01 am UTC

I started teaching myself Rust this afternoon, and plan to spend some time next week doing more. Starter project is to write a spider that tracks all cross-spec links within the set of web specs, to help figure out what will break if someone changes/removes a definition.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

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 » Sat Jul 02, 2016 5:29 am UTC

I've been working on a little database implementation as a Rust learning project during my funemployment. Rust is good times. Still a little rough around the edges, though (type level literals integers would be nice). The borrow checker is a bit hard to get along with at first, but it seems like a pretty cool technology.

EDIT: I can't words good
Last edited by ahammel on Sat Jul 02, 2016 8:10 pm UTC, edited 1 time in total.
He/Him/His/Alex
God damn these electric sex pants!

jareds
Posts: 436
Joined: Wed Jan 03, 2007 3:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby jareds » Sat Jul 02, 2016 5:01 pm UTC

korona wrote:FT: Is throwing from a signal handler allowed in C++?

Context: I have a program that may page fault sometimes (and is able to handle those faults gracefully). I can check if that will happen before I access memory but that is just a (non-negligible) waste of time in 99.999% of all cases. It would be much faster to just take the segfault, throw from it and catch the exception. I also control the standard library so "library function foo is not async-signal-safe" is not a problem here because I can just make them signal safe.

In a signal handler in C++, everything that is allowed in a signal handler in C, using the common subset of C and C++, is allowed, and also C++11 atomic operations that are not member functions are allowed. Anything else is implementation-defined.

I'm not particularly familiar with what support is available for throwing exceptions from a signal handler in various implementations, but GCC has:

Code: Select all

       -fnon-call-exceptions
           Generate code that allows trapping instructions to throw
           exceptions.  Note that this requires platform-specific runtime
           support that does not exist everywhere.  Moreover, it only allows
           trapping instructions to throw exceptions, i.e. memory references
           or floating-point instructions.  It does not allow exceptions to be
           thrown from arbitrary signal handlers such as "SIGALRM".
and this passes a smoke test on Debian 8 (but I'm not sure where the "platform-specific runtime support" exists in general).

Certainly I would expect some compiler option to be required in nearly all implementations for exactly GCC's reason that the implementation needs to know which instructions could be a source of exceptions.

Xanthir wrote:I'm nowhere near experienced in this kind of thing, but I think that systems tend to have a double-fault handler, and even a triple-fault (which is usually just a system crash, as your double-fault handler should *not* be faulting).

You're thinking of hardware exceptions, not C++ language exceptions, which are purely a software construct. (The reason I think you're thinking of hardware exceptions is that your description matches x86, which has a double-fault exception, but a triple-fault will reset the CPU.) In fact, by the point that the OS has delivered a signal, you're only dealing with a software construct, in that you've long since returned from the handler of the hardware exception and a further hardware exception in the signal handler is not a double-fault as far as the hardware is concerned. The OS can allow you to nest signals as deeply as it likes.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Sat Jul 02, 2016 5:56 pm UTC

Wow, thanks a lot, I did not know that GCC had such a flag. That is exactly what I was looking for. :)

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

Re: Coding: Fleeting Thoughts

Postby Xeio » Sat Jul 02, 2016 8:06 pm UTC

Xanthir wrote:I can't tell from your snippet whether this is the case; it depends on whether getting the child resources depends on whatever is async about getting the parent resource.
Each child requires a remote web request to get.

Basically, I have to wait for the parent's request to finish before I can get the children (I need the parent's ID), and since there's no option for requesting multiple levels I have to do it recursively for each level.

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

Re: Coding: Fleeting Thoughts

Postby Xanthir » Sun Jul 03, 2016 6:12 am UTC

Okay, then you're probably doing okay.

I'm still not 100% clear on your code, but do you recursively await for the *entire* tree before starting to work on the first node? That can be improved, if so - kick off the requests asyncly, then do as much work as you can, only awaiting when you actually need the data. If you can do some work on the children immediately, before their children come in, make sure you're timing isn't gating that the wrong way.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

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

Re: Coding: Fleeting Thoughts

Postby Xeio » Tue Jul 05, 2016 3:15 pm UTC

Right now I'm awaiting on all the immediate children of a node coming in at once then processing them. So each node isn't "complete" till all its descendants are retrieved, but it won't care about if siblings are still processing or anything.

I was sort of looking at doing something like await Task.WhenAny(), looping through, clearing out any completed child-fetch tasks (and calling recursion for them), then repeating WhenAny() until I'm out of child tasks. I'm just not entirely sure I like how repeatedly awaiting WhenAny() and managing a list of tasks looks like.

EDIT: It is annoying when IT keeps blocking msdn.microsoft.com for whatever reason.

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

Re: Coding: Fleeting Thoughts

Postby Xeio » Thu Jul 07, 2016 7:24 pm UTC

Ways async can make your life annoying: User changes their password from what you had stored and you just fired off 5 simultaneous web requests...

Account lock powers, activate!

User avatar
Robert'); DROP TABLE *;
Posts: 730
Joined: Mon Sep 08, 2008 6:46 pm UTC
Location: in ur fieldz

Re: Coding: Fleeting Thoughts

Postby Robert'); DROP TABLE *; » Thu Jul 07, 2016 11:21 pm UTC

Xeio wrote:Right now I'm awaiting on all the immediate children of a node coming in at once then processing them. So each node isn't "complete" till all its descendants are retrieved, but it won't care about if siblings are still processing or anything.

I was sort of looking at doing something like await Task.WhenAny(), looping through, clearing out any completed child-fetch tasks (and calling recursion for them), then repeating WhenAny() until I'm out of child tasks. I'm just not entirely sure I like how repeatedly awaiting WhenAny() and managing a list of tasks looks like.


I don't know how serial your processing is, but it sounds like you might be able to get somewhere with a combination of ContinueWith and WhenAll so you don't need to explicitly loop through anything? (The strongly typed version of WhenAll returns an array containing the results of the tasks awaited, so ideally you'd be able to use ContinueWith to process the results up until the point you need shared state, and then do a WhenAll to aggregate it all.)
...And that is how we know the Earth to be banana-shaped.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Fri Jul 08, 2016 11:19 am UTC

When the compiler generates code that is so clever that you have a hard time understanding it yourself:

Code: Select all

if(x) {
    y = 0x28;
}else{
    y = 0x4B;
}


Code: Select all

# input: rdx = x
# output: esi = y
cmp $0x1, %rdx
sbb %esi, %esi
and $0x23, %esi
add $0x28, %esi

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

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Jul 08, 2016 11:55 am UTC

I admit I had to check up on the sbb instruction, but I think it's pretty clear (or it would be, if you used sensible syntax). :D
Spoiler:
esi will be -1 (all bits set) if the comparison is false?
Image

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Fri Jul 08, 2016 12:19 pm UTC

Yeah, that right. But I have to admit that I would not have thought of such an optimization myself. This is one of the reasons why I believe that non-trivial hand crafted assembler will almost always be worse than code generated by a good compiler.
Spoiler:
If x is true then esi becomes 0 after 'ssb' as well as 'and'. Otherwise esi becomes 0xFF after 'sbb' and 0x23 after 'and'.

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

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Jul 08, 2016 12:28 pm UTC

I remember reading a stackoverflow answer where someone asked for a function (in x86) that returned the larger of two inputs.
It was a homework question, but someone did give an answer that used a similar trick (using carry flags after subtractions) to avoid branches.
I believe that someone was Raymond Chen (of Win32 fame).
Image

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

Re: Coding: Fleeting Thoughts

Postby Flumble » Fri Jul 08, 2016 12:39 pm UTC

Is comparing and "sbb"-ing quicker than multiplying? Given that booleans are either 0 or 1, I'd expected something like (forgive me for notation and x86 specifics)

Code: Select all

mul 0x23, %rdx, %esi
sub 0x48, %esi, %esi

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

Re: Coding: Fleeting Thoughts

Postby jaap » Fri Jul 08, 2016 12:43 pm UTC

Flumble wrote:Given that booleans are either 0 or 1

But in this case x is not necessarily boolean. It is presumably an integer type, and in C the "if(x)" construction is an implicit "if(x!=0)".

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

Re: Coding: Fleeting Thoughts

Postby Flumble » Fri Jul 08, 2016 1:01 pm UTC

jaap wrote:
Flumble wrote:Given that booleans are either 0 or 1

But in this case x is not necessarily boolean. It is presumably an integer type, and in C the "if(x)" construction is an implicit "if(x!=0)".

I was basing the assumption on the generated cmp $0x1, %rdx, which only makes sense if the value can only be 0 or 1 (or it's a very weird encoding for a type with a lot of false states and only one true state).

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

Re: Coding: Fleeting Thoughts

Postby jaap » Fri Jul 08, 2016 1:11 pm UTC

Flumble wrote:
jaap wrote:
Flumble wrote:Given that booleans are either 0 or 1

But in this case x is not necessarily boolean. It is presumably an integer type, and in C the "if(x)" construction is an implicit "if(x!=0)".

I was basing the assumption on the generated cmp $0x1, %rdx, which only makes sense if the value can only be 0 or 1 (or it's a very weird encoding for a type with a lot of false states and only one true state).

Oh, right. I hadn't noticed that.

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

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Jul 08, 2016 1:13 pm UTC

The cmp instruction works via subtraction, so the carry flag is set appropriately.

Intel syntax now:

cmp rdx, 1
Subtract 1 from rdx and adjust flag register, but don't store result to rdx.
If rdx > 0 then the carry flag will not be cleared. If rdx == 0 then the carry flag will be set (since the result underflows).

sbb esi, esi
Subtract with borrow - i.e. esi -= (esi + carry flag)
If the carry flag is not set, this will result in esi being 0.
If it is set, it will result in underflow, giving 0xFF..FF
Image

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

Re: Coding: Fleeting Thoughts

Postby Xeio » Fri Jul 08, 2016 1:56 pm UTC

How to want to tear your hair out trying to get a databinding to work: Forget to include "UpdateSourceTrigger=PropertyChanged".

Also, trying to figure out exactly when that needs set... seems to be mainly when I'm using a DataGridTemplateColumn.CellTemplate, whereas most bindings automatically trigger.

EDIT: Somewhat related, I'm using these little work projects where I have a bit more freedom to play around with MVVM too, though I think I'm still putting too much logic into the form... I think... maybe.

commodorejohn
Posts: 1131
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Fri Jul 08, 2016 2:22 pm UTC

korona wrote:Yeah, that right. But I have to admit that I would not have thought of such an optimization myself. This is one of the reasons why I believe that non-trivial hand crafted assembler will almost always be worse than code generated by a good compiler.
Spoiler:
If x is true then esi becomes 0 after 'ssb' as well as 'and'. Otherwise esi becomes 0xFF after 'sbb' and 0x23 after 'and'.

If you were writing hand-crafted assembler in the first place, you'd likely be aware of some of the many optimization guides where this trick and others like it have been known for decades.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Fri Jul 08, 2016 3:18 pm UTC

commodorejohn wrote:
korona wrote:Yeah, that right. But I have to admit that I would not have thought of such an optimization myself. This is one of the reasons why I believe that non-trivial hand crafted assembler will almost always be worse than code generated by a good compiler.
Spoiler:
If x is true then esi becomes 0 after 'ssb' as well as 'and'. Otherwise esi becomes 0xFF after 'sbb' and 0x23 after 'and'.

If you were writing hand-crafted assembler in the first place, you'd likely be aware of some of the many optimization guides where this trick and others like it have been known for decades.

I am actually writing hand crafted assembler but what I have to write is usually restricted to things like interrupt stubs or small routines and inline assembly fragments that access hardware registers. I do not doubt that this trick has been known for decades and that there are programmers that are much more used to writing general purpose code in assembly than I am but even then consistently remembering such constructs is hard (and makes the resulting code quite unreadable if you combine it with good instruction scheduling, but I guess you don't want readable code anyways if you're writing application level code in assembler).

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

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Jul 15, 2016 12:33 pm UTC

TDD: a development technique for doubling the amount of code you have to maintain.

Code: Select all

> cd amazing_project
> sloccount src
1,500
> sloccount tests
3,500
Image

User avatar
ucim
Posts: 6595
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Fri Jul 15, 2016 3:09 pm UTC

I'm sure your project's amazing, but did you really call it "amazing_project"?

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

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 » Sat Jul 16, 2016 3:33 am UTC

Xenomortis wrote:TDD: a development technique for doubling the amount of code you have to maintain.

Code: Select all

> cd amazing_project
> sloccount src
1,500
> sloccount tests
3,500
I really want to instrument a way to collect metrics on test value.

A test isn't helping you if it always passes. It's if it throws too many false positives (bug was in the test, code is fine). It's helping a lot if it fails often because the code it's covering tends to sprout bugs when you change it. I want a little dashboard that gives me the information to say "this test has a thousand lines of hairy setup, fails for no reason during certain phases of the moon, and has never caught a bug. Imma delete it."
He/Him/His/Alex
God damn these electric sex pants!

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

Re: Coding: Fleeting Thoughts

Postby Thesh » Sat Jul 16, 2016 4:39 am UTC

Tests not failing is a good thing not a bad thing; the work has been done and once it is written there is no point in deleting it (and doing so might allow a bug to sleep by in the future).

Ideally when you have test driven development, your tests for a unit should cover every (relevant) code path within the unit, and cover the use-cases that it is designed for.
Summum ius, summa iniuria.

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 » Sat Jul 16, 2016 5:24 am UTC

Thesh wrote:Tests not failing is a good thing not a bad thing;
I'm not saying it's bad, I'm just saying a test that never fails is less valuable than a test that routinely catches bugs.

work has been done and once it is written there is no point in deleting it
Some tests have trivial maintenance costs, but others are slow, or difficult to keep in sync with the code, or consume a lot of money to run.

(and doing so might allow a bug to sleep by in the future).
Maybe, but depending on the situation I might decide that it's worth the risk.
He/Him/His/Alex
God damn these electric sex pants!

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

Re: Coding: Fleeting Thoughts

Postby Thesh » Sat Jul 16, 2016 5:34 am UTC

You don't have to run every test every time. You can always have frequent tests ran on your build server after every build, some ran once per day, and some ran before a release.

If code is frequently changing, then I would argue that that's an even better reason to keep those unit tests. Normally, your unit tests shouldn't change unless a behavior is modified or removed in a way that invalidates the previous test anyway.
Summum ius, summa iniuria.

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

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Jul 18, 2016 9:29 am UTC

Honestly, the most useful tests that guarded against regression were not the "unit" tests, but the "integration" tests.
The unit tests had some value in development (I could quickly verify code I'd just written), but took required a fair amount of mental effort - a lot of mocking was required and it required considerable thought to devise meaningful tests.
But they only really failed as a result of interface change - we made this function return something different, so of course those two tests for that function will fail. But it was the integration tests that reminded me that "that class over there wasn't expecting to receive a two-element tuple".

ucim wrote:I'm sure your project's amazing, but did you really call it "amazing_project"?

I firmly believe in using descriptive_names.
Image

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? » Mon Jul 18, 2016 12:56 pm UTC

Yeah, as a developer, I don't think the primary value of tests is to prevent regression. It's a nice bonus, but the main reason I write tests is that having a working test harness of an appropriate granularity is extremely powerful for quickly debugging code. I use them sort of like a REPL for compiled languages.

Of course this also depends hugely on the testing support in the language. Java, say what you want about the language in general, has amazing test tools. Writing tests in C++ is a bit more of a pain, and the language promotes a different code architecture that is harder to test (I think largely because there's no "free" interface segregation).
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

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 » Mon Jul 18, 2016 2:22 pm UTC

You, sir, name? wrote:Java, say what you want about the language in general[...]

Speaking of which, I've been doing a lot of Java for work lately and I kind of like it? Send help.
He/Him/His/Alex
God damn these electric sex pants!

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

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Jul 18, 2016 2:25 pm UTC

ahammel wrote:
You, sir, name? wrote:Java, say what you want about the language in general[...]

Speaking of which, I've been doing a lot of Java for work lately and I kind of like it? Send help.

ITYM HelpFactory().CreateHelp().Message().Send(TargetFactory().CreateTarget( ArgumentFactory().CreateArgument( NameFactory().CreateName(StringFactory().CreateString("ahammel")).Marshall() ).Marshall() ).ArgumentVerify().Marshall() ).TargetRegister().CheckInvariants().Marshall() ).Async();
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
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? » Mon Jul 18, 2016 2:31 pm UTC

ahammel wrote:
You, sir, name? wrote:Java, say what you want about the language in general[...]

Speaking of which, I've been doing a lot of Java for work lately and I kind of like it? Send help.


Yeah, I've done Java development for a few years now :-/

I think, with a reasonable code base and an IDE that does 99% of the typing for you, it's manageable. I think a lot of the problems with Java are cultural rather than language flaws. For a while there seems to have been a consensus that horrendously misapplying design patterns was the way to go in Java. But good Java developers can produce Java code that isn't comically over-engineered.

That being said, I've seen some shit.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

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

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Jul 18, 2016 2:37 pm UTC

Eh, over half of my frustrations at work are caused by the IDE (I spend a stupid amount of energy being angry with Eclipse).
Not that much is spent being angry at the limitations of Java.

For the past five or so weeks, I was working on a python project at work (the aforementioned "amazing_project"). I just used vim and basic command line tools. I didn't ever have to touch Eclipse. I was happy.
Today things are back to normal. I've spent most of the day being angry with Eclipse. I am not happy.
Image

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? » Mon Jul 18, 2016 2:42 pm UTC

Yeah, Eclipse is a pretty frustrating application. I like IntelliJ quite a lot more.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

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

Re: Coding: Fleeting Thoughts

Postby Xeio » Tue Jul 19, 2016 2:41 pm UTC

Turns out DataContractJsonSerializer can be a little slow when parsing large nested objects, was causing my UI to hang even when the Web Request was all async.

Solution? ContinueWith! Hooray! UI is smooth again.

EDIT: It does come with the cost that now my exceptions are "AggregateExceptions" and I need to handle them differently.

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

Re: Coding: Fleeting Thoughts

Postby Flumble » Tue Jul 19, 2016 4:33 pm UTC

Xeio wrote:Turns out DataContractJsonSerializer can be a little slow when parsing large nested objects, was causing my UI to hang even when the Web Request was all async.

Solution? ContinueWith! Hooray! UI is smooth again.

EDIT: It does come with the cost that now my exceptions are "AggregateExceptions" and I need to handle them differently.

You kids and your newfangled words! (oh well, it's better than making your sentences pointfree)


In other news: why are graphs not a default data structure in <insert language here>? Sure, graphs are just lists of lists or a matrix of edges, but so are dictionaries just lists of pairs and are stacks just lists. A bit of semantics and a few methods/settings to check/ensure properties of a graph and do some traversing/colouring would be really nice.

Tub
Posts: 410
Joined: Wed Jul 27, 2011 3:13 pm UTC

Re: Coding: Fleeting Thoughts

Postby Tub » Tue Jul 19, 2016 6:00 pm UTC

Flumble wrote:Sure, graphs are just lists of lists or a matrix of edges

Which one? And which representation do you expect <insert language here> to support?
Flumble wrote:A bit of semantics and a few methods/settings to check/ensure properties of a graph and do some traversing/colouring would be really nice.

And are your graphs directed or undirected? Do you allow multi-edges? Are your edges weighted? Or can they even contain an arbitrary number of attributes? Are cycles allowed or not?
Pick just one and it's useless for most purposes. Support all of those, and suddenly you either have a deeply nested and slow implementation, or the standard library needs to implement a dozen versions of dijkstra for the different graph types.

It's easy to write a small general-purpose dictionary, but impossible to write a succinct general-purpose graph library. And graphs are useful in fewer applications.

If you just need something simple with a few hundred nodes, I'm sure you can find a library or write one in an afternoon. If you're interested in real graphs (like your favourite social network's friend graph), nothing a standard library could support will suffice.

Flumble wrote:but so are dictionaries just lists of pairs

A proper dictionary has O(log n) complexity for looking up a key/value-pair by key, a list of pairs has O(n).

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

Re: Coding: Fleeting Thoughts

Postby Thesh » Tue Jul 19, 2016 6:04 pm UTC

Most dictionaries are implemented as hash tables and should be more like O(1) barring massive collisions.
Summum ius, summa iniuria.

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

Re: Coding: Fleeting Thoughts

Postby Flumble » Tue Jul 19, 2016 8:49 pm UTC

Tub wrote:And are your graphs directed or undirected? Do you allow multi-edges? Are your edges weighted? Or can they even contain an arbitrary number of attributes? Are cycles allowed or not?

Exactly. A general directed multi-graph with labeled edges, with lots of specializations (as many as the maintainers want to maintain). Just like how other data structures form a hierarchy.

It's true that most of such a library would be sitting ducks in most projects, but I believe it wouldn't be the least used standard library.

Tub wrote:A proper dictionary has O(log n) complexity for looking up a key/value-pair by key, a list of pairs has O(n).

The former only applies if your key type has or is mappable to a (partial) order.
The latter only applies if you don't have random access to the list or the list is unordered.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Tue Jul 19, 2016 10:00 pm UTC

Graph data structures need to be tightly coupled to the problem they want to solve. Even something simple like DFS requires specialized data structures (i.e. a per-node flag that remembers if the node has already been visited yet).


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 16 guests