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
Jabor
Jul 16, 2010

#1 Loser at SpaceChem
i recently replaced a loop-over-everything-in-a-sorted-list hot loop with a log-time thingy instead, which is about the only cs-ey thing I've done in years. Everything else has been "plug Component A into Component B" or "Make Component C by combining Components D, E, F..."

i could even have done this particular problem by plugging the Sorted List component into the Binary Search component, but it turns out that in this particular case just writing the specialized version was much more straightforward than introducing a bunch of wrappers and comparators and stuff to make it work with the generic pre-written component.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Marzzle posted:

can someone show a really stupid example of java lambda stuff because i've googled around for it before and it just sorta assumes you know a bit about them anyway. I actually asked some lovely comp sci ta's and they didn't know that java had lambda expressions but i just wanna car extends vehicle bad programmer example of how they are used and why they are useful since I am p sure my school isn't actually gonna tell me. they seem like they are only good for finding instances of an object in some collection that have properties that fit a specific criteria but it seems like it should probably be able to do a lot more if it was important enough to bring over from other languages. I've been lookin at this

the example literally just above that passage is pretty good

code:
btn.setOnAction(
  event -> System.out.println("Hello World!")
);
you have a callback method that you want to have happen in response to something (for example, in response to a particular button in the ui being clicked). the "normal" java way is some serious kingdom-of-nouns bullshit where you have a ThingDoer interface with a doThing() method, and you create an an anonymous class which overrides doThing() with the code you want to run, and you pass an instance of that class to whatever actually needs it. a lambda is basically syntactic sugar that lets you skip all that pointless boilerplate.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
mathematical operations are totally fine though, right? so for example, if you have some sets, it's totally reasonable to use the + operator to create the union (the additive combination) of those sets. similarly, if you have a ordered collection, it's reasonable to use + to construct the additive combination by appending the contents of another collection.

the real question is why most languages only let you use those operators on a small subset of the types for which they make sense.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
concatenation is a perfectly reasonable additive combination when you're talking about lists of stuff, whether they be lists of tuples, integers, characters, whatever. allowing it for lists of characters but not other lists is a bit weird though.

talking about how concatenation isn't commutative is beside the point really, lots of mathematical operations are commutative over the reals but not other domains, you don't see people claiming matrix multiplication is somehow not multiplication.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Luigi Thirty posted:

Which means the branches at the top are out of range of the last few blocks. I'm pretty sure this isn't the ideal way of doing this. I can't do a JSR off of a compare without spaghetti short jumps to an intermediary subroutine. How should I be doing this?

The easy way of doing a conditional jump to an address you can only reach by an absolute jump is to just do a tiny branch for the jump:

code:
	BNE CarryOn
	JMP WhereYouWantToGo
CarryOn:
There might be a more convenient way to specify it in your assembler.

Jabor fucked around with this message at 05:43 on Apr 26, 2015

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
also you're probably better off using a computed jump into a jump table (or even directly to the relevant code if you're feeling sufficiently Real Programmer) rather than a big ladder of compares and branches

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
I would guess that most big projects that pre-date angular don't currently use it, because rewriting your application just because you can is basically never worth it no matter how much of an improvement the new hotness is. So I guess the answer to your question depends on whether you think any small applications that started development (or had a UI rewrite where it was worth switching toolkits) are actually "important".

(As an aside, this is the same reason Go uptake is slow. If your metric for success is " everyone immediately drops everything to rewrite their already-working code " then you really do belong in this thread.)

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Subjunctive posted:

I think they accidentally used gwt for something once, before they realized it was theirs and stopped.

Funnily enough, I don't see much new development using GWT any more - that particular niche is where angular gets used instead.

A bunch of internal tooling uses angular (actually, internal products tend to be more early-adopter than customer-facing products in general), but there's also stuff like leanback and doubleclick.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Subjunctive posted:

I was interviewing people at FB within a couple weeks of starting. is that supposed to be a bad thing?

Even if their job is specifically to interview candidates for other roles, starting to interview people on the same day you start work seems a little premature.

Starting to interview people a few weeks in seems fine though, depending on your actual job role, how much prep material and support you can get etc..

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
the gopherhouse

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
the lack of generics in go is definitely a pain point, but I find it hard to care when the main reason people say they want it is so they can just keep using their c/java idioms instead of doing it in a way more suited to the language.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

fleshweasel posted:

for integrals it's a little trickier because the definition of the integral is a sum
I imagine the typing I just did on the derivative is lovely enough to read so I'll leave that alone

Antidifferentiation doesn't have a general closed-form solution, but for polynomials it's sufficient to note that differentiating a polynomial gives us a polynomial, and we can do the same thing backwards to find an antiderivative that differentiates to our original function.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

MeruFM posted:

lol at writing maths when the forums don't support latex

um i think you mean LATEX

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Okay, so correct me if anything here isn't what you're actually doing/trying to do...

1. You want to slowly fade from one colour to another, over time
2. You have some sort of message loop that you're using to call your fade function every now and then
3. Your fade function uses static (i.e. global) variables to keep track of how much fading it's already done/how much it still needs to do

I think the first step is to know what structs are and how to use them. A struct is just a way to wrap up a whole bunch of values and pass them around all in one thing. As a warm-up, try writing a struct to represent "colour", and rewrite your existing functions to use it instead of passing around an array of three values.

The next important thing to do after that is to split out the "I want to do a fade from Cyan to Magenta" bit from the "here's what I call every tick to perform one step of the fade". You'll find structs useful here.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
honestly unless you're talking about enormous stack-allocated arrays i'm not sure it really matters if you have an empty stack slot or two in your function. register allocation is the important part of lifetime tracking.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
the early eulers are great for stretching your programming muscles

unfortunately the later ones are way more about mathematical "aha!" moments than anything to do with code

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
java typing was awful when you had to do poo poo like

code:
Map<SomeVerboseTypeName, SomeOtherVerboseGenericType<AndAnotherOne>> map = new HashMap<SomeVerboseTypeName, SomeOtherVerboseGenericType<AndAnotherOne>>();
its fine now tho

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If all these distinct types have a set of methods in common, perhaps that commonality should be encoded in an interface.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Well yeah. It's literally impossible to have a type system that, in a bounded amount of time, decides whether running a program will result in failing a type-check.

Consider the following code:
code:

int test(function f) {
  f()
  return "fail"
}

Determining whether the program actually type-fails in practice is dependent on whether the function you pass into it terminates.

The best you can do is sort programs into "won't fail", " will fail" and "undecided".

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

horse mans posted:

why would you ever choose perl

because it's a practical language for extraction and reporting

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
you can perform in-place updates by calling the appropriate function for the type though (e.g. extend). += etc. is just "you can perform in-place updates in fewer characters, sometimes"

I say "sometimes" because doing poo poo like
code:
lolbutts = (["a", "list"], whatever)
lolbutts[0] += "fart"
just mysteriously doesn't work :iiam:

(the reason it doesn't work is because instead of picking one of the two reasonable options, that is:
- turning "a += b" into "a = a.operator+(b)"
- turning "a += b" into "a.operator+=(b)"
they decided on the shittiest compromise of turning it into "a = a.operator+=(b)")

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

pointsofdata posted:

also I can't help interpreting six and a half figgies or w/e as 6.5=log_10(pay)

that's because that's what it means

the reason it's a ~~yospos meme~~ is because it's making fun of that one guy who thought otherwise and was talking up his 150k salary

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

coffeetable posted:

anything you can put in writing or is it just accumulated experience?

90% of design patterns are "the original way we did this turned out to be unmaintainable poo poo, here's how you should do that sort of thing instead"

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
lol finalizers

at least suppress finalization when the dispose method gets called, otherwise you're paying the cost even when you do clean it up right

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
msdn even tells you how to do it right

code:
public class Whatever : IDisposable {
    protected virtual void Dispose(bool disposing) {
       if (disposing) {
          // call Dispose() on any other disposables
       }
       // clean up unmanaged resources
    }
 
    ~Whatever() {
        Dispose(false);
    }
 
    public void Dispose() {
        Dispose(true);
        GC.SuppressFinalize(this);
    }
}
then you only need to worry about hard-to-reproduce race conditions with things getting cleaned up in the wrong order when you forget to dispose something, instead of, you know, all the other problems finalizers cause

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Putting 'final' on a method parameter is equivalent to putting it on a local variable inside the method - it doesn't actually mean anything at all to code that calls the method.

Everything in Java is passed by value. If you reassign a parameter to be something else (which is the only thing that declaring it final prevents you from doing), that has zero effect on anything outside the method.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Just allocate a big-rear end chunk of heap and point sp at it before jumping into your highly-recursive code, easy

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You can't even write a program to definitively answer "will Program A run forever if given Input B?" in all cases.

That "in all cases" bit is basically the essence of the halting problem. Coming up with solutions for specific subcategories of programs can be interesting, but is kind if unrelated to the general problem.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Space Whale posted:

I guess I don't understand what "all cases" entails.

"All cases" means you want to find a general solution for all possible programs. We can prove that it's not possible to find a solution through contradiction:

- assume a program exists which solves the halting problem
- show that there is at least one program where the above does not give a correct answer

So, let's assume you've written a program which solves the halting problem. Well call this program H. H(A, B) means "does the program A halt when given the input B?".

Let's make a new program, call it G. G(A) is just H(A, A) - "does the program A halt when given itself as input?".

Let's make another new program - call it I. I looks like this:
code:
def I(A):
  if G(A):
    while(true):
      ;
That is to say, it runs forever if A halts, but halts if A runs forever.

So what's the result of I(I)?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

MALE SHOEGAZE posted:

most conditionals can be nested, but not ternaries. the compiler is still in alpha.

Was it trying to do some weird bespoke parsing or something? "<expr> ? <expr> : <expr>" seems like it should nest just fine by default. It might associate the wrong way (see: php), but having it not nest at all seems like it would require explicit effort to make happen.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

fart simpson posted:

why not just write sometihng like if a then "a" else if b then "b" else if c then "c" else "d"

because then it would be a statement, not an expression

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
There are good reasons - in framework code. If your application-developing coworker is writing stuff like that you should run far, far away.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
doesn't include av false-positives, 0/5

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Often it's better to write an API around the database and forbid applications from hitting the database directly. Need to query some new stuff? Come up with a sane way to add that info to the API.

So basically stored procs, except handled by your own code instead of being tied up in the database. Another bonus is that you can relatively easily add authentication etc. to externalize it for client applications, third-party developers and so on.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
I'm sure an internet of ActiveX plugins would be far superior, right?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
i'd say the most likely reason is that the startup programmer is an arrogant idiot (but i repeat myself...)

for example, if I had severe dunning-kruger syndrome and wasn't aware of try-with-resources, I might think that you'd introduced a bug with not cleaning up the file writers. I also might get offended when you fixed parts of my lovely code that weren't intentionally lovely for the sake of the assignment. your rewrite is overall much improved and the criticism you actually received doesn't make much sense.

--

as for my personal criticism of your code, that wacky indentation you used for fields is really bad (it looks kind of cool, but literally nobody wants to spend time maintaining that spacing...), and you should use a FutureTask or something else explicitly cancelable instead of wrangling interrupts yourself.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
writing concurrent code is easy, just do the python method and have a single lock around all the code that shares anything with each other. it's not even that big of a performance issue if the amount of time spent doing that is small compared to the other work a thread does. an example of correct & safe (though not optimal) concurrent code:

code:
Butt getButt() {
  synchronized(this) {
    if (this.butt == null) {
      this.butt = makeButt();
    }
    return this.butt;
  }
}
it's once you start trying to be "clever" with concurrency that you gently caress things up.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Brain Candy posted:

lol, no, this is exactly the problem with Java's java.util.Vector where they synchronized all the methods

Java code:

Vector<V> things = ...

public void threadingIsEasy() {
    for (int i = 0; i < things.size(); ++i ) {
       V v = things.get(i); //Sometimes this throws an exception
       ...
    }
   ...
}

The "easy and correct" mechanism there is ofc:

code:
synchronized(things) {  
    for (int i = 0; i < things.size(); ++i ) {
       V v = things.get(i); //It's safe now
       ...
    }
}
the important thing is you have a single lock you take at the start and release at the end. if you don't try and be "clever" (like, for example, thinking "I don't need to take the lock because the individual methods are synchronized"), you will come up with a correct solution.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Brain Candy posted:

please continue this retarded regression, i want to get you to champion python's GIL

it's straightforward to implement correctly, and the downside is relatively poo poo performance

not sure why you think this is complicated

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

pepito sanchez posted:

and i wasn't trying to implement some dual-pivot / 3-way partition quicksort ala java. gently caress dat. i was showing F# = cleaner, cooler code not too loving hard to understand. anyone including me could just search "F# quicksort implementation" online and get more efficient results but that was missing the point

Actually the point is that functional languages make it really easy to write a bad sorting algorithm that looks kind of like quicksort but isn't. Similar to when people try to write a prime sieve.

Quicksort is an in-place sorting algorithm, if it's not in-place it's not actually quicksort.

  • Locked thread