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
Xarn
Jun 26, 2015

HoboMan posted:

idk, knowing if one of my util functions throws exceptions or just eats them at a glance would be p useful
(because there are processes that if they fail, well we don't really care)

java devs are just dumb+bad in how they use them 99% of the time

Or it rethrows the exception as runtime unchecked exception, because the function signature gets really annoying really fast. :v:

Adbot
ADBOT LOVES YOU

HoboMan
Nov 4, 2010

checked exceptions as a list of recoverable exceptions in a function that if it fails you must try to recover sounds pretty useful to me.
just another way to enforce code rules on your project without having to really remember what they are

i would never put them in a plugin though, you have to make too many assumptions about Other People's Code. that's where they get really miserable to deal with

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Xarn posted:

Or it rethrows the exception as runtime unchecked exception, because the function signature gets really annoying really fast. :v:

Nah. Just declare "throws Exception" and that fixes the function signature problem.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

HoboMan posted:

it's hard to advocate for though since it's basically making the use of exceptions for program flow

this this this

the only legitimate reason to throw an exception is when something happens that is out of both your scope and your control, like an IO error. everything else is a bug

one of my predecessors literally used exceptions as gotos everywhere. in at least two instances he used a try - throw - catch where an if then else would have worked

whenever i have to read his code i remember that he quit because he got cancer and I try to feel bad for him, but for some reason I seem to quietly go on to my next task and skip over the actual "feeling bad" part

hobbesmaster
Jan 28, 2008

so bad coding can give you cancer? or is it just in exceptional cases

Bloody
Mar 3, 2013

i still have no loving idea how to use async poo poo in c# and its extremely frustrating. i think i might even finally have a use case for it too

hobbesmaster
Jan 28, 2008

what kind of async stuff

like my only experience with .net stuff has been the bastardized form of C++/cli but don't you just connect signals to delegates or w/e?

GameCube
Nov 21, 2006

speaking of async, UGH

for my concurrency testing bullshit i'm starting five tasks at once and trying to wait for them all to complete but Task.WaitAll is returning before they all complete. HOW COME

jony neuemonic
Nov 13, 2009

Bloody posted:

i still have no loving idea how to use async poo poo in c# and its extremely frustrating. i think i might even finally have a use case for it too

- anything that returns a task is awaitable
- await is only available in methods marked async

:toot:

Shaggar
Apr 26, 2006
there are tons of gotchas with async like by default if you're doing async stuff w/in a transactionscope weird poo poo will happen so you need to specify that the transactionscope will be doing async poo poo.

GameCube
Nov 21, 2006

code:
    int nextIndex = 0;
    Func<LomarfType, int, int, Action> actionGenerator = (lomarf, index, delay) => async () =>
    {
        await queue.WaitAsync(lomarf);
        // WaitAsync should only return when it's our turn
        Assert.Equal(nextIndex, index);
        // simulate execution
        await Task.Delay(delay * 1000);
        // increment the index counter before dequeuing, which will signal the next waiter
        nextIndex++;
        queue.DequeueLomarf(lomarf);
    };
    
    var tasks = Enumerable.Range(0, delays.Length).Select(x => Task.Factory.StartNew(actionGenerator(lomarfs[x], x, delays[x]))).ToArray();
    
    // execute all tasks simultaneously
    Task.WaitAll(tasks);
    Assert.Equal(nextIndex, delays.Length);
i'm sure it's some dumb bullshit but that's why i'm in this thread

GameCube fucked around with this message at 20:49 on Jul 21, 2016

Bloody
Mar 3, 2013

nextIndex is outside the scope of that lambda and hilarity ensues or something

Bloody
Mar 3, 2013

hobbesmaster posted:

what kind of async stuff

like my only experience with .net stuff has been the bastardized form of C++/cli but don't you just connect signals to delegates or w/e?

lol i dont even really know. i have a custom i/o device that slowly chugs away and right now its handled in its own tx thread so it doesnt slow down everybody else but sometimes this causes a mess and dealing with the threads when i flush or close is also sometimes making poo poo crash in exciting ways and async seems like the magic handwaves to make it all go away

JawnV6
Jul 4, 2004

So hot ...
ive had really good help from the gray c# thread and they seem to know that async/await stuff

Xarn
Jun 26, 2015

ulmont posted:

Nah. Just declare "throws Exception" and that fixes the function signature problem.

I think that at that point, everyone would rather have unchecked exception.

In other words, I am all for it. :v:

GameCube
Nov 21, 2006

hmm actually i wonder if an exception is getting thrown in those tasks that i'm not seeing. wouldn't WaitAll throw that exception though. gently caress

HoboMan
Nov 4, 2010

FUUUUUUUUUUUUUUUUUCK
i just removed the transactions and this poo poo is still broken as gently caress (yay, not my fault?)
but there is some magic db bullshit going on and the dba is out today~

i might actually have to postpone a release
gently caress

Bloody
Mar 3, 2013

nah just ship it broken like everybody else

GameCube
Nov 21, 2006

yeah. you're not thinking agile enough

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
NumberFormatException is the best exception.

GameCube
Nov 21, 2006

yup greythread solved it in five seconds. can't wait on an async void

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

GameCube posted:

yup greythread solved it in five seconds. can't wait on an async void

Async void??? Who did an async void? That's kind of verbotten except for very special circumstances.

GameCube
Nov 21, 2006

i did without realizing it

Soricidus
Oct 21, 2010
freedom-hating statist shill
the only bad thing about checked exceptions is that they don't work very well with java's implementation of lambdas, where what you want is for the lambda to be able to throw any exception that the parent method can handle, but actually it can only throw what its interface declares, and for the standard ones that's nothing.

hope you didn't want to do any io in that foreach!

Bloody
Mar 3, 2013

why do my unit tests occasionally just halt with no given reason
not abort, not fail, just halt. stops everyone else from executing too. wtf

Xarn
Jun 26, 2015

Bloody posted:

why do my unit tests occasionally just halt with no given reason
not abort, not fail, just halt. stops everyone else from executing too. wtf

Werent you testing multithreded stuff? I guess you just found a deadlock. :v:

Bloody
Mar 3, 2013

nah like the test execution halts, not like it hangs. resharper just gives me the little hand and marks the un-run tests "inconclusive"

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

sounds like u have a halting problem

Luigi Thirty
Apr 30, 2006

Emergency confection port.

wish you'd halt and catch fire

comedyblissoption
Mar 15, 2006

exceptions are probably bad b/c they're this extra side channel that people often forget about and arent forced to think about

this extra side channel can often make composing stuff together and creating abstractions a lot more complicated

people (including standard libraries) often abuse exceptions for what should be normal control flow

no one can agree upon what should be normal control flow and what should be exceptions

sometimes you end up having to handle both exceptions and return results for error handling

the alternative is just returning error results on the stack in the vast majority of cases, but maybe that might be bad too for its own reasons. i haven't used it enough to decide yet.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Mr Dog posted:

what concrete application are you interested in



well, graphics is the thing i keep telling myself ill learn when theres time

so basically a vector is a function describing a "line" in n dimensions (which i will just mentally limit to 3 to keep my head unexploded) and when you want to rotate the vector, you're really multiplying it by another vector that represents the "path" of the rotation. this isn't really different from normal multiplication of functions other than that it's a pain in the rear end so matrices can be used as a shorthand form of vector multiplication? does that get near to the idea?

hobbesmaster
Jan 28, 2008

well the path actually needs an extra dimension and is called a quaternion :v:

LordSaturn
Aug 12, 2007

sadly unfunny

LeftistMuslimObama posted:

well, graphics is the thing i keep telling myself ill learn when theres time

so basically a vector is a function describing a "line" in n dimensions (which i will just mentally limit to 3 to keep my head unexploded) and when you want to rotate the vector, you're really multiplying it by another vector that represents the "path" of the rotation. this isn't really different from normal multiplication of functions other than that it's a pain in the rear end so matrices can be used as a shorthand form of vector multiplication? does that get near to the idea?

the transformation is represented as a matrix, not as a vector. (rotations can be represented as a vector of n + 1, but that's wizard poo poo)

applying the transformation to a vector means multiplying the matrix (n by n) by the vector (1 by n) which gives you a new vector (1 by n)

if X and Y are matrices, and V is a vector, X * (Y * V) = (X * Y) * V so it's common to multiply the transformations together, which is equivalent to compositing the functions

EDIT: typo

LordSaturn fucked around with this message at 03:46 on Jul 22, 2016

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

LordSaturn posted:

the transformation is represented as a matrix, not as a vector. (rotations can be represented as a vector of n + 1, but that's wizard poo poo)

applying the transformation to a vector means multiplying the matrix (n by n) by the vector (1 by n) which gives you a new vector (1 by n)

if X and Y are matrices, and V is a vector, X * (Y * Z) = (X * Y) * Z so it's common to multiply the transformations together, which is equivalent to compositing the functions

ok, im sort of following. but why do i need two matrices? if i have this line and i want to rotate it on the screen, isnt that just one transformation?

LordSaturn
Aug 12, 2007

sadly unfunny

LeftistMuslimObama posted:

ok, im sort of following. but why do i need two matrices? if i have this line and i want to rotate it on the screen, isnt that just one transformation?

X can be your camera rotation, Y can be the rotation of the line. Z can be the rotation of the object the line is part of, Q can be the translation due to screen shake, etc etc etc. multiply your total transformation once, then multiply it by every vertex to transform them

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

LordSaturn posted:

X can be your camera rotation, Y can be the rotation of the line. Z can be the rotation of the object the line is part of, Q can be the translation due to screen shake, etc etc etc. multiply your total transformation once, then multiply it by every vertex to transform them

got it. i need a matrix for each "thing" that is happening each frame that changes how the line should be displayed, and since camera movement, movement of the object the line is part of, movement of the scene the line is contained in, etc are all different transformations of the line relative to its screen position they are all separate functions that need to be multiplied together (composed?).

Bloody
Mar 3, 2013

actually if you wanna throw in a translation you gotta go to augmented matrices/vectors for all affine transformations

i think

fritz
Jul 26, 2003

trying to learn myself a scala and so far it's ok but im still on babby's first web scraper and not getting any deeper than map/filter so far

LordSaturn
Aug 12, 2007

sadly unfunny

LeftistMuslimObama posted:

got it. i need a matrix for each "thing" that is happening each frame that changes how the line should be displayed, and since camera movement, movement of the object the line is part of, movement of the scene the line is contained in, etc are all different transformations of the line relative to its screen position they are all separate functions that need to be multiplied together (composed?).

yes. now instead of a line, pretend every vertex is actually a vector drawn from the origin to its point. because it is.

Bloody posted:

actually if you wanna throw in a translation you gotta go to augmented matrices/vectors for all affine transformations

i think

actually this might be true. all I know you can do for sure is scaling and rotation

Adbot
ADBOT LOVES YOU

Sapozhnik
Jan 2, 2005

Nap Ghost

LeftistMuslimObama posted:

got it. i need a matrix for each "thing" that is happening each frame that changes how the line should be displayed, and since camera movement, movement of the object the line is part of, movement of the scene the line is contained in, etc are all different transformations of the line relative to its screen position they are all separate functions that need to be multiplied together (composed?).

Don't worry so much about lines, we're just talking about points here. Rotate all the vertices in an object and you'll rotate the object.

A vector tells you the position of a point. Transforming that vector tells you the new position of that point.

The reason matrices are useful in this situation is that you don't have to, say, scale everything and then rotate everything. You can combine the scaling and the rotation into one matrix ahead of time, and then you only need to apply that one matrix to do both things simultaneously, which is more efficient. The whole discussion actually bottoms out fairly quickly if you're just talking about 3D space because about the only things you can do with 3x3 matrices is rotation, scaling, reflection, and I guess shearing. Beyond that they're not very useful, again, if you just stick to strictly 3D space and ignore the final paragraph of this post.

You can't move things using a matrix, because a matrix can only represent a linear function f(v), and remember how f(Av) = A f(v) must hold for all vectors v and numbers A for that function to be linear? Well, set A = 0. Then f(0 * v) = 0 * f(v), so f(0) = 0 must always always hold. If f(0) gives you something other than 0, then f isn't a linear function and you can't represent it as a matrix. Well, that means you can't move things around with a matrix, you'd have to move from 0 to some place other than 0. Matrices aren't useful here.



... well, sort of. Except you can do a hack where you model everything in four dimensions, and then you can cook up a 4x4 matrix that moves the camera, rotates the camera, and then does a perspective transformation of everything from 3D onto the 2D plane of your screen. Which is much faster than doing all these things separately and keeping track of them all separately. But that's getting a little bit ahead of things, and that's taking a very applied-computer-graphics-programming-oriented view of things as opposed to a pure mathematical view of what's actually going on.

Perspective transformation involves dividing both X and Y by Z which is an extremely non-linear operation but the trick there is that the actual division doesn't happen until you re-interpret your 4D space back into 3D... well, 2D at this point... by dividing X Y and Z by the fourth dimension co-ordinate. It all seems very simple to me after having read up a bit on it but I can see how this would seem incredibly confusing if you're diving straight in and trying to understand the entire stack of concepts all at once

Sapozhnik fucked around with this message at 04:19 on Jul 22, 2016

  • Locked thread