Search found 112 matches

by cogman
Mon May 23, 2011 9:39 pm UTC
Forum: Coding
Topic: A compilation of best programming practices ?
Replies: 17
Views: 4436

Re: A compilation of best programming practices ?

... The art of programming is one where you learn by doing, copying code that you didn't write will NOT teach you programming. Reading others code is invaluable, copying is detrimental. At the same time, you should learn from examples, and you shouldn't reinvent the wheel if someone else did it for...
by cogman
Mon May 23, 2011 7:54 pm UTC
Forum: Coding
Topic: A compilation of best programming practices ?
Replies: 17
Views: 4436

Re: A compilation of best programming practices ?

First, for every hard and fast "you should never/alway do X" there is some exception which invalidates that rule. Next, Every programming language has its merit and no programming language is perfect. Take with a grain of salt the opinion of people who can't find fault with a language or p...
by cogman
Sat Apr 30, 2011 2:50 pm UTC
Forum: Coding
Topic: Intentionally making compile time long
Replies: 40
Views: 7248

Re: Intentionally making compile time long

I know this is going to sound a bit crazy, but you could always try going "above and beyond". If you plan on making programming a career, this is the best way to land a job out of college. My suggestions, try programming a game. Read up on the SDL, OOP, or whatever. If you are finishing in...
by cogman
Fri Mar 11, 2011 12:29 am UTC
Forum: Computer Science
Topic: Removing repeated numbers from a very large list.
Replies: 39
Views: 5808

Re: Removing repeated numbers from a very large list.

Don't use a vector of bool. Bools are not 1 bit, but 8 bytes wide. A vector of bool would not be a manageable size. Rather use a bitset and do what is suggested here. In C++ a vector<bool> has a special implementation that does use only 1 bit per bool. Thats crazy, definitely not what I expected. (...
by cogman
Thu Mar 10, 2011 8:59 pm UTC
Forum: Computer Science
Topic: Removing repeated numbers from a very large list.
Replies: 39
Views: 5808

Re: Removing repeated numbers from a very large list.

Don't use a vector of bool. Bools are not 1 bit, but 8 bytes wide. A vector of bool would not be a manageable size. Rather use a bitset and do what is suggested here. I went out to find some database benchmarks and the best I could find was about 2000 transactions per second. For 2^32 records, that ...
by cogman
Wed Jan 12, 2011 12:09 am UTC
Forum: The Help Desk
Topic: ISP block bypassing
Replies: 13
Views: 4625

Re: ISP block bypassing

Hate to break it to you, but you can't go around your ISP. They are there to stay no matter what. The best you can hope to do is a proxy. Tor is pretty dang near unstoppable.
by cogman
Sun Dec 26, 2010 2:47 pm UTC
Forum: Computer Science
Topic: Greedy Algorithm for change
Replies: 7
Views: 7318

Re: Greedy Algorithm for change

It most likely has to do with the rate of currency change. My be is that so long as each coin is ~5x the next smallest coin, the gready algorithm works for change, it is when they swing to far (10 is too far) that things break down. This is just a guess and is in no way proven.
by cogman
Tue Oct 26, 2010 10:16 pm UTC
Forum: Coding
Topic: Help with optimizing code (VBA)
Replies: 10
Views: 1708

Re: Help with optimizing code (VBA)

A noble effort, Jplus, but that really isn't the issue. Your issue is simple, you are talking with the spread sheet WAY too much. This is EXTREMELY slow. It is sort of like taking a 45 min bus ride to town to get a grape, returning home, eating the grape, and then taking the bus ride again to get an...
by cogman
Sun Oct 24, 2010 3:18 pm UTC
Forum: Coding
Topic: Language for theoretical physics
Replies: 24
Views: 3287

Re: Language for theoretical physics

I haven't used it myself, but I have heard nothing but complaints about it from physics majors I know. Your mileage may vary, I suppose. It is slower then say C++ (but so is python), however, it gets the job done just like any other procedural language. Couple that with the fact that it has the use...
by cogman
Sun Oct 24, 2010 2:33 pm UTC
Forum: Coding
Topic: Language for theoretical physics
Replies: 24
Views: 3287

Re: Language for theoretical physics

C and Python are both quite compatible with universities, but for your purposes, Haskell might be a good choice. It's not a commonly used language, but universities love it for how deep into CS theory you can go with it. Math translates to Haskell way nicer than any other language I have ever used,...
by cogman
Thu Oct 21, 2010 5:09 pm UTC
Forum: Coding
Topic: Would haskell make me a better programmer?
Replies: 21
Views: 5317

Re: Would haskell make me a better programmer?

One language I would suggest learning is assembly (Even though many programmers cringe at the thought). And not just assembly for assemblies sake, but learn what your compiler is ACTUALLY spitting out. It really changes your view on what code looks like and gives you a deeper understanding on what e...
by cogman
Fri Sep 10, 2010 1:07 pm UTC
Forum: Computer Science
Topic: Combination of sines function for CPU usage
Replies: 4
Views: 1394

Re: Combination of sines function for CPU usage

Most likely it is coming from something along the lines of a Do processing <- High CPU usage Load Data <- low CPU usage sort of pipeline. The CPU is running at a fairly constant speed and the data loading is also going fairly constant causing a sort of sine like CPU usage. Other thoughts include the...
by cogman
Thu Sep 02, 2010 6:04 pm UTC
Forum: Computer Science
Topic: Unary Processor
Replies: 37
Views: 6846

Re: Unary Processor

I'm not convinced that actually satisfies a unary computer. In unary, you have one state (on) as cogman said. This means you have one piece of information to work with: 1. Quintopia, you said: "Let's assume that there is an EOF or BOF character." I will assume that. In order to recognise ...
by cogman
Thu Sep 02, 2010 2:42 pm UTC
Forum: Computer Science
Topic: Unary Processor
Replies: 37
Views: 6846

Re: Unary Processor

I'm sorry, but WHAT? You CAN'T have a unary computer that does anything. Ever every single symbol is the same, you end up with a system that has no way of telling what is going on. The moment you introduce any sort of method to distinguish one instruction from another, you have created a binary syst...
by cogman
Wed Sep 01, 2010 2:15 pm UTC
Forum: Coding
Topic: Haskell as a first language.
Replies: 10
Views: 4337

Re: Haskell as a first language.

Why does everyone recommend python? Hardly the best starting language. If you teach someone python, then they're probably not going to learn the underlying things that it does for you. You'll learn to code, and that's it, but you'll only be able to code in Python, you won't get any of the cross-lan...
by cogman
Sun Aug 29, 2010 5:46 am UTC
Forum: Coding
Topic: Lots of questions
Replies: 14
Views: 2712

Re: Lots of questions

1. You don't. Rather, you use reference variables (same thing, only different) http://csis.pace.edu/~bergin/papers/JavaPointerTraps.html 2. I believe so, but am not familiar enough with the IDE to tell you how to do it. Most have a next step key/button you push after hitting a breakpoint. For VS it ...
by cogman
Sun Aug 29, 2010 5:35 am UTC
Forum: Computer Science
Topic: Karnaugh map.
Replies: 7
Views: 2003

Re: Karnaugh map.

What's so hard about gray codes? So long as you realize that each step is only flipping one bit, the progression seams pretty natural to me. Most aren't going to require you to come up with your own gray code, rather they will present the progression and have you identify what it is.
by cogman
Sat Aug 28, 2010 2:39 am UTC
Forum: Coding
Topic: The C Killer
Replies: 62
Views: 10126

Re: The C Killer

Ok, lets address these "issues" one at a time. I don't know about C, but C++ certainly does have these problems. C might have these problems too, but I don't have enough experience to know offhand. struct Foo { Foo(int x) { cout << "struct Foo" << endl; } }; void Foo(int x) { cou...
by cogman
Fri Aug 27, 2010 10:57 pm UTC
Forum: Coding
Topic: The C Killer
Replies: 62
Views: 10126

Re: The C Killer

Var, why is it there? What does it do other than needlessly add a keyword? I can only assume something about making writing the compiler easier? Quite possible. C is plagued by the fact that its grammar is inherently ambiguous. For example: f(a); might call a function called "f" or define...
by cogman
Fri Aug 27, 2010 6:47 pm UTC
Forum: Coding
Topic: The C Killer
Replies: 62
Views: 10126

Re: The C Killer

Honestly, I would only change a few things with C rather then replace it all together. For one, I would make threading easier/a built in feature. When the standard C library was written, multithreading wasn't a big deal. Now, it is the way forward. How would I do this? I don't know, something like b...
by cogman
Tue Aug 24, 2010 4:20 pm UTC
Forum: Computer Science
Topic: Ackermann Function
Replies: 7
Views: 2859

Re: Ackermann Function

#include <iostream> #include <map> using namespace std; struct ackVal { bool valid; int value; }; map <int, map < int, ackVal > > ackMap; int ackManFunc(int m, int n) { if (ackMap[m][n].valid) { return ackMap[m][n].value; } else if (m == 0) { return n + 1; } else if (n == 0) { ackMap[m][n].valid = ...
by cogman
Sat Aug 14, 2010 1:40 pm UTC
Forum: Coding
Topic: [Unnecessarily-] Compact coding tricks
Replies: 112
Views: 17534

Re: [Unnecessarily-] Compact coding tricks

A bit shift will not work here. The problem is that carry over from the first color will bleed into the second. IE if the bit stream looks like this 1101|0001|0110 Then a bitshift of 1 would produce this 0110|1000|1011 Notice that the only color that became darker was the first, the other two becam...
by cogman
Sat Aug 14, 2010 1:20 pm UTC
Forum: Coding
Topic: [Unnecessarily-] Compact coding tricks
Replies: 112
Views: 17534

Re: [Unnecessarily-] Compact coding tricks

So, well we're at it, given a hexadecamal representation of a color (0xrrggbb) what's the best why to create a color to use as an outline without disassembling it into three RBG values? It doesn't have to be an exact amount darker or lighter, so long as there's contrast. Right now I'm using (color ...
by cogman
Sat Aug 14, 2010 3:32 am UTC
Forum: Coding
Topic: [Unnecessarily-] Compact coding tricks
Replies: 112
Views: 17534

Re: [Unnecessarily-] Compact coding tricks

void swapint(int& a, int& b) { a ^= b; b ^= a; a ^= b; } That doesn't work for all inputs. Hell, for ints there's no reason not to use a temp variable, it's (usually) only 4 bytes. Seems to be the definition of "unnecessary". :D xoring does have the advantage of not having to touc...
by cogman
Sat Aug 14, 2010 12:30 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 10016
Views: 2031540

Re: Coding: Fleeting Thoughts

VS is the greatest IDE on the planet... End of story.
by cogman
Fri Aug 13, 2010 10:27 pm UTC
Forum: Coding
Topic: Halting problem coding challenge
Replies: 59
Views: 8472

Re: Halting problem coding challenge

coltz(integer n) { if (n % 2 == 0) return coltz(n / 2); else if (n != 1) return 1; else return coltz(3 * n + 1); } call coltz(203948752093847520394875234531415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679...
by cogman
Fri Aug 13, 2010 8:44 pm UTC
Forum: Coding
Topic: Halting problem coding challenge
Replies: 59
Views: 8472

Re: Halting problem coding challenge

coltz(integer n) { if (n % 2 == 0) return coltz(n / 2); else if (n == 1) return 1; else return coltz(3 * n + 1); } call coltz(20394875209384752039487523453141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359...
by cogman
Wed Aug 11, 2010 7:50 pm UTC
Forum: Coding
Topic: [Unnecessarily-] Compact coding tricks
Replies: 112
Views: 17534

Re: [Unnecessarily-] Compact coding tricks

void swapint(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

int fact(int n) { return n <= 1 ? 1 : n * fact(n -1 ) }
by cogman
Mon Aug 02, 2010 5:30 pm UTC
Forum: Science
Topic: Would it be possible for humans to pollute the sun?
Replies: 55
Views: 5940

Re: Would it be possible for humans to pollute the sun?

Trash is only resources that we haven't figured out how to reprocess. Sending them off to the big incinerator in the sky would be a waste.
by cogman
Sat Jul 31, 2010 4:00 am UTC
Forum: News & Articles
Topic: Richard Stalman does an AMA
Replies: 58
Views: 9546

Re: Richard Stalman does an AMA

I really don't understand where you are getting this. GNU.org under the URL he mentions in the article starts out with: Many people believe that the spirit of the GNU Project is that you should not charge money for distributing copies of software, or that you should charge as little as possible — j...
by cogman
Sat Jul 31, 2010 12:57 am UTC
Forum: News & Articles
Topic: Richard Stalman does an AMA
Replies: 58
Views: 9546

Re: Richard Stalman does an AMA

Anyone that sells software is being unethical? Yeah, UmmHmmm. Money makes software advance. No, this is the notion he is trying to discourage. He doesn't care about gratis. He cares about libre. He's fine if you sell your software. He's not fine if you make it proprietary. The comment you pointed o...
by cogman
Fri Jul 30, 2010 4:16 pm UTC
Forum: News & Articles
Topic: Richard Stalman does an AMA
Replies: 58
Views: 9546

Re: Richard Stalman does an AMA

I think all proprietary software is unethical, even if it meets the definition of open source. (Some proprietary programs do.) So even though the question asks about "proprietary closed-source software", my response is about proprietary software, whether it is closed-source or not. Stallm...
by cogman
Tue Jul 20, 2010 1:34 pm UTC
Forum: Coding
Topic: What code/software license should I use?
Replies: 5
Views: 1687

Re: What code/software license should I use?

The zLib licence or the MIT licence sounds to be about what you want.
by cogman
Thu Jul 15, 2010 6:26 pm UTC
Forum: Computer Science
Topic: Your best Fibonacci algorithm?
Replies: 24
Views: 11787

Re: You're best Fibonacci algorithm?

It really depends on how often you are calling the Fibonacci function. If you are going to compute a random set of fib numbers, I find the dynamic programming approach to be a useful one.

If you are just spitting out every fib number 1 to 100, then doing the iterative method will be the fastest.
by cogman
Wed Jul 14, 2010 10:40 pm UTC
Forum: Coding
Topic: Looking for a C++ function
Replies: 6
Views: 1311

Re: Looking for a C++ function

Fstreams is what you are looking for (ifstream to be specific). Though you can't separate with commas. If the data is seperated with spaces and returns, the ifstream object will behave just wonderfully. *snip ifstream inherits get from istream so why attempt to (poorly) recreate the functionality t...
by cogman
Wed Jul 14, 2010 9:26 pm UTC
Forum: Coding
Topic: Looking for a C++ function
Replies: 6
Views: 1311

Re: Looking for a C++ function

Fstreams is what you are looking for (ifstream to be specific). Though you can't separate with commas. If the data is seperated with spaces and returns, the ifstream object will behave just wonderfully. IE fstream bob("some File"); int val string thing int otherVal bob >> val; bob >> thing...
by cogman
Tue Jul 13, 2010 1:06 pm UTC
Forum: Coding
Topic: There's more to programming that someone's not telling me.
Replies: 8
Views: 2163

Re: There's more to programming that someone's not telling m

In short, yes. The Win32 API is huge . For almost every feature of the OS, there is an associated official, documented API that you can use to programatically control it. If you want to find a particular window, you can use EnumWindows to enumerate through all open windows or you can use FindWindow...
by cogman
Fri Jul 09, 2010 6:29 pm UTC
Forum: Computer Science
Topic: OTP encryption and true randomness
Replies: 9
Views: 2547

Re: OTP encryption and true randomness

Thanks for the help! I think it's hilarious (and indicative of our noob-ility) that my friend and I modified an OTP to make it more convenient until it became another common cipher entirely. Would the usage of different languages be helpful in making a running key cipher unlikely to be cracked? Say...
by cogman
Thu Jul 08, 2010 6:05 pm UTC
Forum: Coding
Topic: Object Oriented programming and relational databases
Replies: 9
Views: 2959

Re: Object Oriented programming and relational databases

Agree with Berengal, they might be using an ORM, like Hibernate, to lazily fetch data. Or not. Hard to say. Everything they are doing is pretty much stored procedures, regardless of whether they are right for the job. That's another gripe I have, and this applies to a ton of people. Fanatical use o...
by cogman
Mon Jul 05, 2010 7:21 pm UTC
Forum: Coding
Topic: Object Oriented programming and relational databases
Replies: 9
Views: 2959

Re: Object Oriented programming and relational databases

sounds like they need to twerk their design. They are currently using accessors in a sub-optimal way (Loading everything at object instanciation) While it generally makes sense to get globs of contiuous data and then process, it sounds like the data is non-continuous (IE in different tables). A bett...

Go to advanced search