Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Sapozhnik
Jan 2, 2005

Nap Ghost
Programming is better suited to being taught by means of apprenticeships rather than degrees

this is how people learn to program in practice anyway, just in an informal and inefficient way

Adbot
ADBOT LOVES YOU

Sapozhnik
Jan 2, 2005

Nap Ghost
in C:

why does char ** cast to void * but not to void **, that's kind of annoying.

is there some strict aliasing poo poo i'm supposed to be aware of

i mean, sure i can throw a (char **) cast in there but this probably throws a warning for a reason and i'd rather not be visited by the spooky scary ghost of undefined behaviour

Sapozhnik
Jan 2, 2005

Nap Ghost
I have a question about paging results sets returned by a REST server.

Let's say I'm writing a REST service. Clients can request a large list of rows, and the server will return a few initial matches along with a link where the client can find more (the link's query parameters contain all of the state required to resume the iteration), the target of that link contains more results and another link and so on. This is all well and good, except there's a problem if any other clients come along and insert or delete rows behind the client's current position: inserting a new row will cause the next page to start with a repeat of the previous page's last row, which might not be so bad, but deleting a row will cause the client to skip one record, which kinda sucks. Statelessness in the REST server is the name of the game here so the server isn't going to keep a long-running database transaction open for the client.

One way to mitigate this problem would be to use soft deletes, then add a creation and deletion timestamp to every row. No big deal, I've got some data service wrappers around my ORM, I can add that fairly easily: every query is made with reference to a particular point in time, and the data services only return records whose liveness extent (from creation time to deletion time, where a record that has not been deleted has a logical deletion time of positive infinity) contains that point. Except that a delete transaction can race with a start-of-iteration reader transaction: in between the delete timestamp being determined and the delete actually getting committed any initial result sets returned by the server will point to a hole (because the continuation URL contains the point in time T1 at which the read transaction began, which is greater than the as-yet-uncommitted delete timestamp T0).

There don't seem to be any particularly pleasant solutions to this problem. Change strategy and make the server read ahead by one page, then return a half-open range [next_begin, next_end) range of row IDs? Seems great until next_begin gets deleted out from under you and you have no idea where you are. Also, if the client can control the sort order then bracketing the result set using two row IDs leads to some really nasty SQL probably involving window functions and poo poo. Taking an exclusive lock on the table prior to timestamping the delete and committing it seems like it would work, but that's a little extreme. Blurring the liveness extents and allowing the server to return rows that were deleted "recently" before the point-in-time specified in the query string is sloppy because then you have to choose a sensible value for "recently" but I guess that's the ugly-but-effective solution.

I feel stupid because I'm sure this is a problem that was well understood and solved before I was even born, but I can't find any meaningful answers with a bit of casual Googling. Most articles about pagination in REST APIs seem blissfully unaware that this problem even exists.

Sapozhnik
Jan 2, 2005

Nap Ghost

MononcQc posted:

https://www.citusdata.com/blog/1872-joe-nelson/409-five-ways-paginate-postgres-basic-exotic is a decent resource to see a few of the options available in the context of postgres. A lot of what you can build in terms of paginations will have equivalents in that list, but that's not all that's possible.

The actual storage mechanism you use may very well limit what's practical pagination for you.

Interesting link, wasn't aware of the ctid thing.

The solutions presented aren't super satisfactory but it's definitely good food for thought. Thanks!

Sapozhnik
Jan 2, 2005

Nap Ghost
my thought process was something like "what if i do snapshot isolation except not really". you can't keep a transaction open for an extended period of time so you have to fake it up somehow and make some compromises along the way.

if i can return all the rows at least once but some of them might change in the course of the iteration then i can live with that. i can probably do that if i don't give the client the ability to sort the data server-side but instead order the rows by creation timestamp, pass the last row id in a url state parameter, and use soft deletes so i can still pick up where i left off even if the anchor row gets deleted.

or maybe do the opposite: let the client sort stuff but then not paginate and require the client to do "pagination" by constraining the result set using things it knows already.

but you can't do both without full historical snapshots of every row which is just a pain in the dick and not something that sql databases are good at to begin with.

Sapozhnik
Jan 2, 2005

Nap Ghost

JewKiller 3000 posted:

window functions are great, dehumanize yourself

For batch process reporting, sure. For use from an ORM? Every single one I know of be all "lol gently caress this poo poo i'm out"

Sapozhnik
Jan 2, 2005

Nap Ghost

Breakfast All Day posted:

my favorite window function is seeing the beauty of nature that i never interact with because i chose to work with computers

Sapozhnik
Jan 2, 2005

Nap Ghost
one day i will learn to stop hanging myself with stupid estimates for poo poo

(this whole rest api thing isn't even work related, more of a thought experiment).

Sapozhnik
Jan 2, 2005

Nap Ghost
yeah that sounds great until the first time you look at a commented struct and there's just barf everywhere

or have to distinguish between 0 and O, or l and I.

proportional fonts for programming, loving lol

hipster childs just have to find as many ways as possible to be special

Sapozhnik
Jan 2, 2005

Nap Ghost
I like the GNU build system a lot (autoconf, automake, pkgconfig even though that's technically separate. lol forever if you use libtool).

idk why, i know it is a yog shoggoth m4 abomination on the inside. but as a user it's so goddamn cool. openembedded be like "oh hey, looks like you used autoconf etc like a non-idiot, let me just make use of all the machinery it gives you for free to turn your source code into a cross-compiled set of packages with -debug and -devel packages totally automatically".

even the built in test runner is... somewhat serviceable, and there's a small piece of m4 you can drop in to automatically run everything through valgrind for you

i suppose it's only fitting that somebody as bad at posting as i am likes something that abbreviates to gbs

(openembedded is horrifying. but everything else that does what it does is even worse)

Sapozhnik
Jan 2, 2005

Nap Ghost
async/await owns very hard indeed and i hope java gets it soon

(so, probably sometime around 2019 at the earliest :smith: )

it's going to be a bit tough with java though since java's standard Future interface is so utterly awful and java 8's CompletableFuture took it in a very bad direction.

Sapozhnik
Jan 2, 2005

Nap Ghost

HoboMan posted:

it's me, i'm the rear end in a top hat who worries about performance in enterprise-grade internal apps.

*waits 15 minutes after login for his garbage fuckbonfire corporate pc to become responsive*

Sapozhnik
Jan 2, 2005

Nap Ghost

LordSaturn posted:

since I now have an excuse to mention monads:

someone in a gamedev thread was talking about LINQ and mentioned that buttList.Select( Foo ).Where( Bar ).From( Bat ).ToList() doesn't actually execute Foo Bar or Bat until you call ToList, and then iterates over the input exactly once, and suddenly I understood why anyone cares about monads

that's not monads though that's lazy evaluation

Sapozhnik
Jan 2, 2005

Nap Ghost

comedyblissoption posted:

games unfortunately afaik want you to minimize heap usage due to the garbage collector pauses so you might be hosed there

lolunity

Sapozhnik
Jan 2, 2005

Nap Ghost
yeah c++ definitely has a machismo thing going on

c is still the only game in town for embdev though.

Sapozhnik
Jan 2, 2005

Nap Ghost
anybody who calls themselves a c++ expert is a liar

Sapozhnik
Jan 2, 2005

Nap Ghost

Shaggar posted:

don't use sbt or gradle, use maven.

Sapozhnik
Jan 2, 2005

Nap Ghost
Homogeneous co-ordinates are also a thing to look into.

You have a point in a 4D co-ordinate space (x, y, z, w) which maps to the 3D point (x/w, y/w, z/w). This allows you to do perspective foreshortening and affine transformations (i.e. a combination of a scale and an offset, something you can use to move things around as well as scaling/spinning/shearing/whatever them around their center) using a single 4x4 matrix. You can't normally do this with 3x3 matrices because they are basically a generic shorthand for linear functions of vectors, and you can't make a linear function that moves things around because it will necessarily need to map zero to something other than zero.

But you can cheat by having a fake zero point at (0,0,0,1) which then becomes (0/1, 0/1, 0/1) = (0,0,0) in the final dehomogenization(?) step. I'm not too knowledgeable on the actual math behind it but homogeneous co-ordinates are a sort of mathematical hack to make affine transformations linear.

Then there's quaternions, which are basically a completely different way of doing rotations but idk how they apply to other kinds of transforms. Quaternions are useful because you can smoothly blend between two rotations expressed as quaternions whereas you can't really do that with matrices anywhere near as easily. But actually applying them to a 3-vector using a Hamilton product requires slightly more arithmetic operations then the equivalent multiplication by a 3x3 matrix

(disclaimer: it's been a long time since I looked into this stuff so I may well be talking complete poo poo)

Sapozhnik
Jan 2, 2005

Nap Ghost

mutability and ownership are completely orthogonal

doing some embedded C at the moment and most of my pain points at the moment are making sure i can roll things back and deallocate at every single point where something might fail. not a fun time.

arguably exceptions and try-with-resources blocks actually make code harder to understand compared to a bunch of gotos into a sequence of rollback operations.

Sapozhnik
Jan 2, 2005

Nap Ghost

Bloody posted:

if you're doing dynamic allocation in embedded I feel bad for you son

embedded-ish, this particular thing runs Linux because it needs to do HTTPS amongst other things.

I'm prototyping on a Raspberry Pi but it's potentially going to scale down pretty hard from there.

Sapozhnik
Jan 2, 2005

Nap Ghost

VikingofRock posted:

I disagree. Iterators make your code more flexible, easier to refactor, and the issues with invalidation aren't really worse than anything else in C++.

If you're defining a function that can take an arbitrary class of iterator as a parameter then that function needs to be a template and you're going to bloat the hell out of your code with all of its different instantiations. Plus your compile time will continue to take a poo poo.

If that's not something you care about then why are you using C++, use Java or Python or something.

Sapozhnik
Jan 2, 2005

Nap Ghost
Quaternions are actually really cool and basically a 3D extension of complex numbers and how you'd model rotation with those, and there's not much to complex numbers other than "a complex number is basically like a 2D number and you can express them in cartesian or polar forms and the way in which those two forms are related is really cool and ~*elegant*~". But you need some basic calculus to understand the relationship and also the most common practical application of complex numbers is in AC circuits where you use them to extend the rules for DC resistance into AC impedance. Which most people don't have to deal with. Whereas at least negative numbers have a really pressing practical application in most peoples' lives in the form of debt.

When I was in high school I thought basic calculus and linear algebra and complex numbers were the coolest goddamn thing. Particularly linear algebra because I really wanted to write a 3D rasterizer and nobody would teach me the mathematics behind it and told me to do my algebra homework instead. So when I went to university I chose to do a joint Comp Sci and Mathematics degree. This turned out to be a horrible mistake.

Sapozhnik
Jan 2, 2005

Nap Ghost
I'd much rather install a service written in Go on my server than one written in loving PHP

Sapozhnik
Jan 2, 2005

Nap Ghost
what was that quote about google designing go for lovely programmers fresh out of college?

Sapozhnik
Jan 2, 2005

Nap Ghost

VikingofRock posted:

I think the basic theory of quaternions isn't that complicated if you are already comfortable with complex numbers. Instead of having numbers of the form (a + bi) you have (a + bi + cj + dk). Addition works in the intuitive way. For multiplying, it's just a few simple rules. i*i = j*j = k*k = -1. When you multiply them in the i->j->k->i order you get the next one in that sequence: i*j = k, j*k = i, k*i = j. When you multiply them in the reverse order (i -> k -> j -> i), you get a negative out in front: i*k = -j, k*j = -i, j*i = -k. For conjugation you just switch the sign of the i/j/k terms, so the conjugate of (a + bi + cj + dk) is (a - bi - cj - dk). The norm of (a + bi + cj + dk) is sqrt(a^2 + b^2 + c^2 + d^2). You can draw pretty clear analogues of these to complex numbers as well.

It's the applications of quaternions that I wish I knew more about. Also as a physicist I've always thought it would be real neat to come up with a representation of GR using quaternions that was as tidy as using complex numbers to represent E&M stuff, but alas I am a mere experimentalist who is leaving the field after I graduate, and my eyes glaze over whenever I read the heavy theory papers, so I guess I will leave that to the theorists.

Apparently Maxwell wrote the initial version of his field equations using quaternions and it made everyone's head hurt a whole heck of a lot until complex analysis got invented and the equations got recast into the more understandable modern form

Sapozhnik
Jan 2, 2005

Nap Ghost
2D rotation using complex numbers:

A complex number is a two-dimensional number built by adding some multiple of i to a number on the real number line to send it up off the number line and onto the 2D complex plane. i is this weird thing that has the property i*i = -1. So like, x + iy for some real numbers x and y is a complex number. It's a 2D number, w/e. Standard arithmetic works as you'd expect, though you have to take a sideways step if you're trying to do division, which involves a "conjugate" (you flip the sign in the middle, change the + to a - or vice versa)

Ae^{i\theta} = A\cos\theta + iA\sin\theta. Easily proven by considering the Taylor series for exp, cos, and sin and the fact that i*i = -1. So you can write a complex number using cartesian co-ordinates or as an angle and a distance from the origin, and that equation tells you how to convert between the two forms, just apply algebra and basic trig.

If you encode a point as a cartesian complex number and then multiply it by a complex number (call it "r") whose distance from the origin ("modulus") is 1 then you'll rotate by r's counterclockwise angle from the positive real axis (its "argument"). So if you really wanted to do 2D rotation using complex numbers that's how you'd do it. If the modulus wasn't 1 then you'd also scale by the modulus in the process. Whatever.

Complex multiplication is commutative just like real multiplication. Stacking up a bunch of 2D rotations is also commutative. Good to know.




3D rotation using quaternions:

Three imaginary units instead of one: ii = jj = kk = ijk = -1. Fiddle with that and you'll see that these are not commutative, so multiplying on the left gives you a different answer to multiplying on the right. aaaag that's weird. Yeah well matrices also have the same problem, and so does 3D rotation: change the order of a sequence of 3D rotations and you end up facing in a different direction at the end.

Quaternion is something like w + ix + jy + kz. w is the real bit, everything else is the imaginary bit. Vectors are encoded as purely imaginary quaternions (w = 0).

Let's say you want to a thing that rotates other things by \theta radians about an arbitrary unit vector (x,y,z). That thing looks like

q = e^{\frac{\theta}{2}(ix + jy + kz)} = \cos \frac{\theta}{2} + (ix + jy +kz) \sin \frac{\theta}{2}

Why theta divided by 2? I dunno, it's just like that. The important thing is that you have to divide theta by two to compute q and then you evaluate the right hand cartesian side to get tuple of four reals. That's a rotation quaternion. Unlike a quaternion vector it has both a real and an imaginary part. How do you use that to rotate something? Take an imaginary vector v that you want to rotate and calculate qvq^{*}. q^{*} is the quaternion conjugate and it's just like the complex conjugate: flip the sign in the middle of the equation above. Why does qvq^{*} rotate v by q? Because gently caress you.

Why use them instead of matrices? Because multiplying (combining) a bunch of rotation quaternions together is faster than doing the same thing with matrices, which is handy if you want something to be rotating constantly. Also because you can tween between two rotation quaternions whereas you can't really do that with matrices.

idk if any of that helps. probably not.

Sapozhnik
Jan 2, 2005

Nap Ghost

Shaggar posted:

git is so bad

it's a bit sucky, but the better (hg) is the enemy of the good (git)

Sapozhnik
Jan 2, 2005

Nap Ghost

Wheany posted:

here is a short text about git's inconsistent command line options:

http://git.661346.n2.nabble.com/Git-s-inconsistent-command-line-options-td7638178.html

Seems like a healthy project to me actually.

They're polite about it, aware that it's a loving mess at the moment, and are at least thinking about ways to make it be less of a loving mess without breaking everybody's IDE integration in the process. That email chain is fairly recent.

Sapozhnik
Jan 2, 2005

Nap Ghost

GameCube posted:

lol this might be it. God dammit

lol this is shameful

wouldn't it be great if http actually already had a dedicated status code for a uri that's too long? no, surely the protocol's designers would never think of doing that.

Sapozhnik
Jan 2, 2005

Nap Ghost

Progressive JPEG posted:

lol if every commit isn't just swearing with increasing intensity

Sapozhnik
Jan 2, 2005

Nap Ghost
I'm gonna open source some hobby code I wrote a while back and the poo poo I was writing even five years ago is goddamn embarassing. And it's all there in the Git history for people to point and laugh at.

At least I'm in the right thread!

Sapozhnik
Jan 2, 2005

Nap Ghost

HoboMan posted:

indeed, note the two git status in mine. just to be sure

e: also lol if you don't have a properly configured gitignore file and can just go
code:
# git add ./
every time and not think about it ever again

look at this scrub who doesn't know about git commit -a

Sapozhnik
Jan 2, 2005

Nap Ghost

Bloody posted:

i dont know what tags are for tbh

"This is the exact code we released when we made release 4.20.69"

Sapozhnik
Jan 2, 2005

Nap Ghost

Finster Dexter posted:

The only redeeming feature of Angular 2.0 imho is that it's written in typescript.

what are its non-redeeming features

Sapozhnik
Jan 2, 2005

Nap Ghost
ugh git reset --hard HEAD^ just ate my entire working tree when I wanted to just discard my latest commit fml

Sapozhnik
Jan 2, 2005

Nap Ghost

VikingofRock posted:

I still don't understand why you would be force pushing to a shared repository anyways. That just seems like a bad idea.

Private topic branches that you want backed up to the central server. If nobody other than you is touching a branch then force-pushing is fine.

Sapozhnik
Jan 2, 2005

Nap Ghost

HoboMan posted:

foreign key constraints are annoying

:wideniussay:

Sapozhnik
Jan 2, 2005

Nap Ghost
just cut to the chase and create a single FACTS(ID, KEY, VAL) table

who needs SQL anyway!

Sapozhnik
Jan 2, 2005

Nap Ghost
[making inlining decisions based on the number of characters in the source text is a little goofy]

no poo poo...

Adbot
ADBOT LOVES YOU

Sapozhnik
Jan 2, 2005

Nap Ghost

Luigi Thirty posted:

hmm

since a 3-vertex polygon is always planar shouldn't I be able to linear interpolate Z rather than running full calculations for every point inside the polygon

I need to do some more reading

Barycentric rendering is poo poo-slow yes.

Apply a perspective transform first to get screen X,Y co-ordinates (but keep the Z around because you'll need it later), then sort the triangle's vertices by Y co-ordinate. Split the triangle into an upper half triangle and a lower half triangle with a horizontal line running through the middle vertex as the common edge.

For each scan line in each half triangle, determine the start and end of the scan line using Bresenham's line drawing algorithm. Then you're just drawing a series of horizontal lines. Do your Z-buffer test for each pixel and then apply perspective-correct interpolation to whatever vertex attributes (texture co-ordinates u,v for texturing and/or normals for lighting) and then stuff those into your "pixel shader".

Sapozhnik fucked around with this message at 05:09 on Jul 19, 2016

  • Locked thread