Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 590 591 [592] 593 594 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 883063 times)

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8865 on: January 25, 2016, 07:01:58 pm »

It is valid in JavaScript at least, and for once even returns a sensible value: NaN.  I half expected it to return 0 or something equally stupid.

Meanwhile, I'm kind of disappointed that the rage thread was closed down, because after working on my dissertation research more today I legitimately wanted to throw my computer many times.  I was tasked with adding some profiling code to a popular genetic database search tool known as BLAST, which is written in an amalgamation of C and C++.  I just had to time two things:

1. The amount of time spent doing some string tokenization / comparison.
2. The amount of time spent reading database records off of the disk.

After 10 hours I nearly gave up.  It took me 5 hours to figure out how to just compile the single binary I needed to work on instead of the whole thing, which was necessary because the regular build took 90 minutes to complete and generates 4.2GB of binaries.  I only needed 1 out of the 31 programs compiled.  It took me those 5 hours to figure out that there were 75 separate internally built libraries without comprehensive makefile coverage, meaning that updating the source file didn't rebuild anything, much less the internal libraries and final binary.  So I wrote a shell script that deleted several files and ran multiple make commands, and it still takes several minutes to compile.

After figuring that out, getting step 1 above was simple at least.

Step 2 I nearly gave up on after 4 hours of searching files for fread() or ifstream or fstream or any other indication of code that was doing file reads, running it in GDB and stepping through call stacks in vain hope of finding something.  After I hit 18 levels deep in a call stack that ended up in several .hpp template headers, I finally gave up and just ran it through Valgrind with the Callgrind tool so I could look at a call graph and figure out where the disk reads were happening.  Oh... at that point I realized it was all mmap()ed, so of course I'd never see any fread()s or the equivalent.

I screamed internally a lot and ended up wrapping timing code around what I hoped was the code that read the mmap()ed file, which is now giving me fishy looking numbers.  I guess it's possible that it can read a 3.7 GB database file's contents in 12 seconds, but I don't know if I trust it.

Worse yet, I discovered that this thing has some kind of software managed cache and garbage collector, which I really need to disable or cripple so I can compare the results against my own research.

I wouldn't wish this on my worst enemy.  I can't comprehend how anyone on the NCBI team even managed to put this thing together, much less maintain it.  It's truly terrifying - so many C macros and faux C++ objects and inheritance using function pointers... and it's even mashed up with real C++ code.  I don't know why they have this horrible mix when it could all be C++.

It's also little wonder nobody learns C or C++ in college anymore.  Who would want to deal with this unless they had no choice?
Logged
Through pain, I find wisdom.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8866 on: January 26, 2016, 02:50:13 am »

so, I'm learning glsl. found this shadertoy.com

/LoSboccacc copies pastes furiously
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8867 on: January 26, 2016, 03:34:57 am »

Shadertoy is interesting! It has two downsides though. The first is no vertex control, in that you basically only have a single rectangle that fills your entire screen. Second is no custom textures or sources.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8868 on: January 26, 2016, 04:12:01 am »

Shadertoy is interesting! It has two downsides though. The first is no vertex control, in that you basically only have a single rectangle that fills your entire screen. Second is no custom textures or sources.


yeah but the limitations make them ready to use for effects, I'm using some of those with phaser.js and they port beautifully.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #8869 on: January 26, 2016, 02:29:51 pm »

Recompiling a C++ project in Visual Studio 2015. Looks like they actually managed to break some of the SFINAE that was possible from 2013.

Sigh...one of these days Visual Studio will have good SFINAE support. Oh the template metamagic we will work on that day!
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8870 on: January 26, 2016, 03:08:22 pm »

Yeah, I put it off for as long as I could.  I hoped we'd be able to get enough results for my dissertation from just my own code, but while I was able to roughly replicate how it worked, plus the changes for my research, we really needed to compare against the real thing.

I knew it was going to suck, and it did.

But still, if I were planning on going into academia I would be tempted to use it as a cautionary example of over engineering when teaching.  There are some 10 or so C++ classes or C pseudoclasses involved in reading a sequence of data out of the database, and it takes more than 20 function calls.  I understand that having a database abstraction layer is useful, but there are some wrapper classes that seem completely pointless (such as the database class that wraps around the database volume class, which does all of the work, or the NcbiIfstream class that wraps around the C++ standard library ifstream class and does nothing special).

Amusingly there is also redundant code all over the place.  There are several classes for handling file I/O that have nothing to do with each other, and while there is a FastaReader class for interpreting queries in the FASTA format, the database code doesn't use that reader and instead handles things its own way despite consuming FASTA databases.
Logged
Through pain, I find wisdom.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8871 on: January 26, 2016, 05:08:34 pm »

I don't really think that bad engineering is specifically a C++ thing. Try maintaining any large project written by someone else and it's going to be a huge pain in the ass no matter what language. People often want blame the chosen language for bad decisions: it's buck-passing - it's easier to say "we should have used Python instead of c++" than to say "our ideas about how to structure this program were utterly retarded from the start, and we had no idea of the scope of the problem". Yeah, but they would have delivered the same thing but in retarded Python if they didn't use retarded c++.

 If everyone jumps to the "next big thing" language, we're just going to hear about how awful that language is in 5-10 years.

The big advantage of shifting to a new language isn't whatever fancy features they offer, it's that it forces everyone to throw out all their code and start from scratch, though that can be a double-edged sword.
« Last Edit: January 26, 2016, 05:16:57 pm by Reelya »
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8872 on: January 26, 2016, 05:16:23 pm »

Old code is needlessly complex code.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8873 on: January 26, 2016, 05:25:05 pm »

BTW, mmap doesn't read the whole file - it creates a mapping between memory address space and the file. You'd then use random access reads/writes to work with the data you need from within that.

So mmap'ing a 3.7GB file is not the same as reading 3.7GB, it's more akin to just opening the file in read/write mode.
« Last Edit: January 26, 2016, 05:26:38 pm by Reelya »
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8874 on: January 26, 2016, 06:05:24 pm »

That's what threw me off for so long initially as I was trying to find the code responsible for reading from the disk.  I didn't even realize it was mmap()ing the file until many hours into the search.  That weird wrapper class for ifstream really made me mad because it confused me further into assuming that there was code somewhere doing ifstream.read() when there wasn't.  Or, you know, the other file I/O code that wasn't used at all.

At first I was worried that I wouldn't be able to profile it after all, but then I realized that I could just insert gettimeofday() calls around the cache read method and it would work.  Presumably any page faults handled by the OS or anything else causing a disk read would be timed, so that was good enough.

Quote
I don't really think that bad engineering is specifically a C++ thing. Try maintaining any large project written by someone else and it's going to be a huge pain in the ass no matter what language. People often want blame the chosen language for bad decisions: it's buck-passing - it's easier to say "we should have used Python instead of c++" than to say "our ideas about how to structure this program were utterly retarded from the start, and we had no idea of the scope of the problem". Yeah, but they would have delivered the same thing but in retarded Python if they didn't use retarded c++.

Oh, absolutely.  My initial grumpiness was mostly targeted at C and C++ because of the compilation problems I mentioned, but over engineering is absolutely a language agnostic problem.  I've seen some pretty horrifying PHP and JavaScript libraries in my time too, just nothing quite this gigantic, sprawling and incomprehensible.
Logged
Through pain, I find wisdom.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8875 on: January 26, 2016, 06:54:29 pm »

Like the source code on google.com.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8876 on: January 26, 2016, 07:10:46 pm »

That's more minified than optimized.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8877 on: January 26, 2016, 07:16:49 pm »

Google.com isn't "over-optimized" because somewhere down the line, the consumer ends up paying for every byte that gets transferred. Even squeezing one byte off the worlds most popular webpage would probably allow billions of extra page requests per year.

Nullsrc

  • Bay Watcher
  • A Euclidean Plane Crash
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8878 on: January 26, 2016, 08:09:52 pm »

Personally, my most hated thing is when some system tries to take one kind of code and make it look like another. Case referenced being the code library for my robotics competition, which has a C++ port and a Java port. We chose to use C++ because none of us were very familiar with Java and we weren't a fan of the structure of Java code (or having to deal with the strange idea of running Java stuff on an ARM machine). Turns out the C++ port is basically C++ syntax with Java-style procedures (which are mandatory), with the worst of both. I can't read that code for the life of me.

See also "we should be like python."
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8879 on: January 26, 2016, 08:35:17 pm »

Ah, the horrors that can be inflicted by the C and C++ preprocessors is legendary in that respect.  I read an account once of someone who knew (I think) Pascal who defined tons of macros that transformed if () {} blocks by removing the braces and replacing them with some syntax from Pascal.  The end result was something no C or Pascal programmer would really understand.

There was also someone who defined a macro that replaced the -> operator with the "thy" operator.  Or some craziness like that.  I think the point was to remove an indirection operator somehow but can't remember the full context.
Logged
Through pain, I find wisdom.
Pages: 1 ... 590 591 [592] 593 594 ... 796