Page 138 of 251

Re: Coding: Fleeting Thoughts

Posted: Thu Jun 13, 2013 8:49 am UTC
by Xenomortis
I hate Paypal.
Their documentation is a mess; it's confusing, incomplete and spread over several websites (some of which no longer exist).
Every time I think I've got a handle on the situation, something rears its head and blocks my way again.

Oh, and the testing suite is shit too, so I'm never going to be convinced that it will all work together.

Re: Coding: Fleeting Thoughts

Posted: Thu Jun 13, 2013 9:04 am UTC
by Maelstrom.
Xenomortis wrote:I hate Paypal.
Their documentation is a mess; it's confusing, incomplete and spread over several websites (some of which no longer exist).
Every time I think I've got a handle on the situation, something rears its head and blocks my way again.

Oh, and the testing suite is shit too, so I'm never going to be convinced that it will all work together.

Not to mention the different versions of the API currently active. The documentation is fairly random as to which versions of the API it is documenting, with various features being enabled over time in different versions, but old documentation still saying to use the old versions. It is a nightmare.

Re: Coding: Fleeting Thoughts

Posted: Thu Jun 13, 2013 9:21 am UTC
by Xenomortis
Compound that with the fact that I don't even know which version I have or how old it is. I think I've a handle on what it is, but I'm still hazy on how much it matches the more recent APIs (it doesn't correspond to anything on their github account).
Nor do I know what the situation was years ago when Paypal was offered previously to our customers (apparently our company has been offering users the option to pay with paypal intermittently - so I have to handle those).


Edit:
I think that I might, just maybe, have a grip on this all.
But I still need to confirm what IPN message I'm going to get...

Re: Coding: Fleeting Thoughts

Posted: Sun Jun 16, 2013 9:16 pm UTC
by Aaeriele
Xenomortis wrote:But I still need to confirm what IPN message I'm going to get...


Isn't that what the sandbox is for?

Re: Coding: Fleeting Thoughts

Posted: Sun Jun 16, 2013 10:23 pm UTC
by Xenomortis
Aaeriele wrote:
Xenomortis wrote:But I still need to confirm what IPN message I'm going to get...


Isn't that what the sandbox is for?


As far as I know, that can tell me which each one looks like, not which ones I'm going to get.

Re: Coding: Fleeting Thoughts

Posted: Wed Jun 19, 2013 2:55 pm UTC
by TheChewanater
FT: I really shouldn't find this UI code as funny as I do.

Code: Select all

  setTouchable(Touchable.childrenOnly); 

Re: Coding: Fleeting Thoughts

Posted: Wed Jun 19, 2013 3:39 pm UTC
by Xeio
Yes, yes you should.

Because without context it's hilarious.

Re: Coding: Fleeting Thoughts

Posted: Thu Jun 20, 2013 10:11 pm UTC
by AlexTheSeal
There are lots of strange and alarming things about JavaScript, but the fact that almost any Unicode character is permissible in variable names has got to be way up there on the list.

Re: Coding: Fleeting Thoughts

Posted: Thu Jun 20, 2013 11:47 pm UTC
by phlip
But Unicode variable names are so useful...

But more seriously, it's a lot like Unicode anywhere else... useful, but abusable.

Re: Coding: Fleeting Thoughts

Posted: Fri Jun 21, 2013 6:42 am UTC
by korona
Just don't use unicode variable names. The single most evil statement in JavaScript is certainly with(...) { }.
Aside from that JavaScript has a really clear and nice object model.

Re: Coding: Fleeting Thoughts

Posted: Fri Jun 21, 2013 6:56 am UTC
by phlip
korona wrote:The single most evil statement in JavaScript is certainly with(...) { }.

Agreed, though document.write() is a close second.

VB's With block is possibly one of the few things I actually like about that language, because it wasn't ambiguous:

Code: Select all

With SomeObj
  Print SomeVar  ' is unambiguously another variable
  Print .SomeProp  ' is unambiguously SomeObj.SomeProp
End With
I don't know why more languages don't have something similar to this... it's a useful shorthand, and it's syntactic sugar that can easily compile away. In JS, however, it's much more ambiguous and dynamic:

Code: Select all

with (someobj)
{
  print(somevar); // is another variable only because someobj.somevar doesn't exist
  print(someprop); // is someobj.someprop only because it exists
}
which means that if someobj.somevar ever gets created in the future (possibly in an entirely different piece of code, or even a JS version upgrade if someobj is a built-in type) then suddenly the code stops working.

Re: Coding: Fleeting Thoughts

Posted: Fri Jun 21, 2013 8:05 am UTC
by mr-mitch
What's the best way to cache memory to disk? I'm trying to allocate too much memory for my own good and it's throwing bad_alloc. I've changed this to a simple caching process (separate into blocks, and write the current block/read the next block as needed and also allocating some memory to help in transitions, the look-back is very small) but the performance is still lacking. How would you do it?

Re: Coding: Fleeting Thoughts

Posted: Fri Jun 21, 2013 10:10 am UTC
by headprogrammingczar
phlip wrote:

Code: Select all

with (someobj)
{
  print(somevar); // is another variable only because someobj.somevar doesn't exist
  print(someprop); // is someobj.someprop only because it exists
}


Don't forget that someobj can carry a redefinition of print().

Re: Coding: Fleeting Thoughts

Posted: Fri Jun 21, 2013 1:30 pm UTC
by Xenomortis
There are too many magic strings in our codebase, and I am not clever enough to remember them all without constantly looking up them up in their database (which may or may not reveal their meaning) or asking the guy next to me (who's away for two weeks).
And I cannot think of a "tidy" way of simulating an Enum of strings in .NET
And even if I could, it'd leave things in a horribly inconsistent state (or more inconsistent state).

Re: Coding: Fleeting Thoughts

Posted: Fri Jun 21, 2013 2:43 pm UTC
by Xeio
Static class of string constants? Not a good way to do printing strings, but if you have string codes or something that pattern seems to work close enough to an enum.

Or did you specifically want strong typing to pass these around? You could use an enum and some type of name string attribute like this though I'd generally not want to do that if you don't need the int values of the enum.

Re: Coding: Fleeting Thoughts

Posted: Fri Jun 21, 2013 3:15 pm UTC
by Xenomortis
Mostly I just wanted a meaningful name that would show up in Intellisense.
A simple static class is probably good enough.

Re: Coding: Fleeting Thoughts

Posted: Fri Jun 21, 2013 8:15 pm UTC
by AlexTheSeal
korona wrote:Just don't use unicode variable names.


I don't intend to, but I don't want anyone else to, either.

I think I just want there to be a realtime style checker installed in all text editors that flags JavaScript code that violates Douglas Crockford's rules for good JS programming from JavaScript: The Good Parts, kind of like how flycheck does for Python code that violates the PEP8 style guide.

Re: Coding: Fleeting Thoughts

Posted: Sun Jun 23, 2013 10:28 pm UTC
by flownt
mr-mitch wrote:What's the best way to cache memory to disk? I'm trying to allocate too much memory for my own good and it's throwing bad_alloc. I've changed this to a simple caching process (separate into blocks, and write the current block/read the next block as needed and also allocating some memory to help in transitions, the look-back is very small) but the performance is still lacking. How would you do it?


Don't. Get your virtual memory to do it for you. (Enable swapping if you haven't already)

Re: Coding: Fleeting Thoughts

Posted: Tue Jun 25, 2013 9:37 pm UTC
by b.i.o
AlexTheSeal wrote:I think I just want there to be a realtime style checker installed in all text editors that flags JavaScript code that violates Douglas Crockford's rules for good JS programming from JavaScript: The Good Parts, kind of like how flycheck does for Python code that violates the PEP8 style guide.

Syntastic will do almost that for Vim. It only flags errors when you save, but that's probably good enough. There are included plugins for jslint, jshint, and many other language/linter combinations.

Re: Coding: Fleeting Thoughts

Posted: Tue Jun 25, 2013 9:56 pm UTC
by Xeio
AlexTheSeal wrote:I think I just want there to be a realtime style checker installed in all text editors that flags JavaScript code that violates Douglas Crockford's rules for good JS programming from JavaScript: The Good Parts, kind of like how flycheck does for Python code that violates the PEP8 style guide.

Is this right? I already don't like this style.
Crockford wrote:The var statements should be the first statements in the function body.

It is preferred that each variable be given its own line and comment. They should be listed in alphabetical order.

Re: Coding: Fleeting Thoughts

Posted: Wed Jun 26, 2013 2:43 am UTC
by sparkyb
I saw someone tweet:
Programming Skills: PRIMARILY RUBY AND PYTHON BUT I CAN USE ANY TYPE OF GEM TO CONTROL ANY TYPE OF SNAKE


So I replied:
So Perl and ASP would also be a valid combination?

Re: Coding: Fleeting Thoughts

Posted: Wed Jun 26, 2013 7:09 am UTC
by Xanthir
Bravo, sir.

Re: Coding: Fleeting Thoughts

Posted: Wed Jun 26, 2013 7:28 am UTC
by Thesh
Since "classic" ASP can be used with any scripting engine built for Active Scripting, Perl, Python, and JScript included, you can actually use ASP+Perl; It's the most vile thing imaginable, but it's completely valid.

Re: Coding: Fleeting Thoughts

Posted: Wed Jun 26, 2013 8:00 am UTC
by Xenomortis
I need to learn those, just to be able to use that line.

Re: Coding: Fleeting Thoughts

Posted: Thu Jun 27, 2013 1:41 pm UTC
by AlexTheSeal
Xeio wrote:Is this right? I already don't like this style.
Crockford wrote:The var statements should be the first statements in the function body.

It is preferred that each variable be given its own line and comment. They should be listed in alphabetical order.


What don't you like, the first part or the second? The second is kind of anal, I admit, but being strict about "things that ought to go on separate lines" and "things that shouldn't" is part of avoiding errors due to silent semicolon insertion by the interpreter. The point of the first part is to avoid implicit variable hoisting--local variables are always in scope at the beginning of the block in which they are declared anyway, so Crockford's saying you should make that explicit.

Re: Coding: Fleeting Thoughts

Posted: Thu Jun 27, 2013 1:54 pm UTC
by Xeio
AlexTheSeal wrote:What don't you like, the first part or the second? The second is kind of anal, I admit, but being strict about "things that ought to go on separate lines" and "things that shouldn't" is part of avoiding errors due to silent semicolon insertion by the interpreter. The point of the first part is to avoid implicit variable hoisting--local variables are always in scope at the beginning of the block in which they are declared anyway, so Crockford's saying you should make that explicit.
Both parts.

Variable declarations should be close to use to make it easy to understand. You shouldn't base your style guidelines how programmers from other languages might misread your code at the cost of making it harder to read to developers who know what they're doing. They're called idioms for a reason.

I can only assume the first suggestion causes the second, that now you need to explain what every variable does in a comment, but this should easily understandable with a name and its usage (which is why it shouldn't be so far from the usage). It also promotes useless comments.

Re: Coding: Fleeting Thoughts

Posted: Thu Jun 27, 2013 7:59 pm UTC
by korona
Xeio wrote:
AlexTheSeal wrote:What don't you like, the first part or the second? The second is kind of anal, I admit, but being strict about "things that ought to go on separate lines" and "things that shouldn't" is part of avoiding errors due to silent semicolon insertion by the interpreter. The point of the first part is to avoid implicit variable hoisting--local variables are always in scope at the beginning of the block in which they are declared anyway, so Crockford's saying you should make that explicit.
Both parts.

Variable declarations should be close to use to make it easy to understand. You shouldn't base your style guidelines how programmers from other languages might misread your code at the cost of making it harder to read to developers who know what they're doing. They're called idioms for a reason.

I can only assume the first suggestion causes the second, that now you need to explain what every variable does in a comment, but this should easily understandable with a name and its usage (which is why it shouldn't be so far from the usage). It also promotes useless comments.

Yeah, I second that. Even though JavaScript variables are bound to the function scope and not to the block scope it makes sense to declare them where they are used and not at the start of a function. You could use strict mode if you want to make sure you don't accidentally create new global variables.

Re: Coding: Fleeting Thoughts

Posted: Mon Jul 01, 2013 5:30 pm UTC
by Snark
Cross posting from Forum Games in case any of you would like some coding distractions: viewtopic.php?f=14&t=103385

Re: Coding: Fleeting Thoughts

Posted: Mon Jul 01, 2013 6:46 pm UTC
by Xeio
I don't really like that Visibility is not a boolean in XAML. I'd guess because they may have originally planned for there to be "hidden but not collapsed" value but it makes databindings slightly less neat. :|

Well, at least there's converters (and MS provided a BooleanToVisibilityConverter in the framework, at least).

I find myself wanting a generics version of IValueConverter in the standard library though, rather than everything being passed as objects.

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 11:49 am UTC
by Xenomortis
How to utterly destroy the performance of your computer.

Code: Select all

void separate(char *s, char *d, char t)
{
    while(*d++ = *s++) *s++ = t;
}


What amazes me is how utterly this killed my computer's performance. After about 10 minutes I managed to confirm terminating the process in Task Manager (twice!), but it didn't work.

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 12:25 pm UTC
by korona
What is that code supposed to do? It copies the char at s to the char at d, increments both pointers, writes t to the new location of s and increments s again. That does not sound like a meaningful operation.

No CPU bound task should be able to destroy your computer's performance in such a way. What OS are you using? I always had the impression that Window's scheduler is not that good anyways...

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 12:33 pm UTC
by Xenomortis
It was supposed to insert the parameter 't' between every character in string s and store the result in string d.
But there's a typo: *s++ = t should be *d++ = t.
(It will leave a copy of t at the end of the string too, but it's trivial to remove).

And yeah, this is Windows. I don't feel like running the exact code again to see if it was a fluke of events.

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 1:19 pm UTC
by sparkyb
As it is written, if the length of s is odd, this will overrun the end of the s, write t to areas of memory after s that you probably shouldn't touch, and possibly go on forever unless it happens to hit another null byte. This is why you should declare s as const char*. Since it is meant to be source only, you should not be able to write to it.

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 1:22 pm UTC
by Xenomortis
That is what happened.
What surprised me is that it didn't just crash or hang for a bit (and then crash), but obliterated performance - near 100% memory usage and CPU usage was spiking all over the place.
For around about 40 minutes before I came back from lunch and rebooted the machine.

(Of course, that is perfectly valid behaviour).

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 3:45 pm UTC
by Xeio
I don't know what the point of this cast is.

Code: Select all

string name = "@BRANCHID" + (object) index;

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 4:09 pm UTC
by EvanED
Xenomortis wrote:How to utterly destroy the performance of your computer.

Code: Select all

void separate(char *s, char *d, char t)
{
    while(*d++ = *s++) *s++ = t;
}


What amazes me is how utterly this killed my computer's performance. After about 10 minutes I managed to confirm terminating the process in Task Manager (twice!), but it didn't work.

Yeah that's really weird. It "should have" crashed.

Did you see how much memory it was taking up? Did it go on a spree where for some reason it was allocating more and more memory instead of crashing?

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 5:10 pm UTC
by sparkyb
EvanED wrote:Did you see how much memory it was taking up? Did it go on a spree where for some reason it was allocating more and more memory instead of crashing?


It isn't allocating any memory, it is just writing into unallocated (at least not to it) memory. There's a decent chance it would crash, but it depends on what is in memory after it, and honestly I would have more likely expected it to just hit a null byte terminate sooner.

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 5:20 pm UTC
by Xenomortis
There was no allocation. The strings were on the stack and the memory footprint shown in the task manager's processes list was tiny.
But the memory usage displayed on the performance screen was maxed. And CPU usage was fluctuating all over the place (hitting 90-100% regularly) on a quadcore machine.

Edit:
I cannot replicate it on my home machine.

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 5:29 pm UTC
by Dr. Willpower
Xeio wrote:I don't know what the point of this cast is.

Code: Select all

string name = "@BRANCHID" + (object) index;


If this is Java, it seems like they wanted to force a call to the object.toString() method. This is supposed to be a unique identifier of some sort?

Re: Coding: Fleeting Thoughts

Posted: Tue Jul 02, 2013 6:26 pm UTC
by Xeio
It's C# so it's always going to be the int value (index is an int, if that my not have been clear).

The string is just a SQL query parameter. I don't think you can parameterize a list in an IN statement so I don't see any issue with that. It's just weird they're upcasting an integer.