What do you do when you encounter a tricky problem? [closed] - theory

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
What do you do when you encounter a programming problem that is really hard for you to solve, and you have no idea yet?
Usually, how do you solve it at last?
NOTES:
Could someone introduce something about problem solving practice?

If I can, I leave it alone for a while. Often the solution will pop into my head when I least expect it. (If only we always had the luxury of waiting - often we don't.)
Edit: Another hugely useful thing to do is describe the problem to someone else. Even if they can't help, the very act of explaining it to someone who's unfamiliar with the problem will often clarify things in your mind. Sometimes you get straight to a solution that way, without the other person saying a word. 8-)

I just think it over when a pencil and paper.
Break it down into each part
Look at what parts I know
Research parts I don't
Put it all together
Profit
For me the trick is breaking it into manageable bits.
-- Edit
I must agree with the poster above about talking to someone else, as well. Even if you don't have anyone you can talk to, explain it to a fluffy toy, and the answer will often become obvious.

I find using a whiteboard to explain the problem to someone else very useful.

Sometimes I'll search Stack Overflow to see if anyone has encountered the same or a similar problem; if they haven't, I'll sometimes post a question about it.

The book Peopleware put it in a nice way, that despite being a different context also works here.
The manager's function, they write, is
not to make people work but to make it
possible for people to work.
In this case you are your own manager, so its up to you to make it possible for yourself to work. If its something difficult you are struggling with, then you need to listen to yourself.. what is it you need in order to get started solving it.
For me, it can be that a major class in the project has the wrong name and is inelegant. In order to solve the problem in an elegant way these needs to be fixed first, otherwise it will end out as a half baked solution.
10 cents

For many problems, writing unit tests can help. Break it down (as silky suggests) and try writing tests for the various pieces. Then write code to make the tests pass. Check out some of the literature on TDD.
Writing throwaway "spike" code is also a handy way to figure out new things.

Well, it depends on the kind of problem, whether it's something you can research. For the things you can't, often specific design problems where I have problems keeping all the factors in mind at once, I've found two methods to work well:
Get rid of all possible distractions (computer, phone, people), e.g find an empty conference room. Take along pen and paper and draw a free-form diagram of the factors involved in the problem; sometimes tables also work well. I've found that the ability to concentrate hard without distractions and the graphical representation usually enable me to find a solution.
For really hard problems, sleep over it. Maybe that's just me, but I sometimes come up with the best ideas when I think about something in that half-dazed state right before I fall asleep - and strangely, I can always remember them come morning.

Related

How do I determine the best loop type to use

What is the method by which a programmer selects the style of loop to use?
I have been looking around but I can't seem to get a straight answer. I understand that you can wrangle most looping styles into working for any particular problem, but when I "guess" a good loop, everything just goes well.
My question is...Is there a formal methodology to determine the best type of loop to at least start with?
I'm currently studying Ruby and sometimes not knowing when to enumerate and when to use a more manual loop i.e. a while loop.
Articles, old posts or good books would all be valid answers.
Thanks!

Rotate a node so it points to a specific position in SceneKit

I have a node and I want it's peak point to a specific position (coordinates). How can I do that? So far, I have tried noting because I have no clue how can I do that. Any suggestions?
What you want to SCNConstraint, and more specifically SCNLookAtConstraint.
There are a few similar questions on StackOverflow and examples in both SceneKit WWDC demos.
Next time you ask a question here, make sure you have a specific problem, and do as much research as you can. Show you did all of that, and you won't get downvoted!
If you encounters problems with the constraints, make sure to check if it has been asked here first. Good luck!

Follow original author's coding style? Even if it is horrible / lazy / makes your eyes bleed? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
When contributing to a very old, and apparently no longer maintained, open-source or public domain project, is it suggested practice to follow the original author's coding style even if it is terrible?
More importantly, are there any reasons why one would want to follow the original author's coding style rather than clean it up significantly?
Follow the original coding style. It is far, far better to be consistent, even if it's not pretty to you.
If you do decide to clean up the coding style, do it separately from any other changes. Don't clutter up source control diff's with style changes. Make one (or several) checkins where the only thing you're doing is changing code style. Do not mix in real changes with meaningless changes, it makes it impossible to locate relevant changes when reviewing source control commits.
If you know that it's unmaintained, and you're making changes to it, then I suspect that you'll become the defacto owner/maintainer going forward.
So, that said, I'd e-mail the original author/maintainer, see what they think about the formatting or style changes, and go forward with guns blazing.
If you're not submitting patches, then no. Run it through a code filter and automatically format the code in your preferred style, then hack away.
If checking into source control, you may want to leave it alone as all the style changes will make comparing to previous versions impossible.
If you do want to change the style do it with the baseline code before you make any other changes and then check it in.
Then check it out and make your coding changes. That way it will be easier to track your changes from the point you took it over.
I personally would leave the style alone unless you are making significant changes.
As stated by others, ensure that any style modifications are checked in to your version control system separately from your functional modifications.
However, my suggestion is to be bold and clean up the code as you see fit; "Leave the campsite cleaner than you found it". Cheesy, but true ;)
Just make sure that you are prepared to defend your changes ;)
Heck no! Whatever you do don't make it worse for heavens sake!
If you're adding your own code do it in your own style. This will at least make part of the codebase easy for you to maintain and understand. If you're making minor updates to existing code then you may want to follow that style.
I'm in the same boat, I have to maintain an ancient, business critical, Access 2 based system which is a complete mishmash of styles.
If it's not even maintained why are you worrying about it?
I'd write using my own preferred style, and clean up any code I had to work with. I do that regularly at work even...
Well, I'd say if you are just making a small modification within say a function, it might be clearer to go along with the bad style.
If you create new methods, classes, properties, etc., use a clear, efficient style. You might add a comment at the start of these sections, so that others can understand what's going on. You might even add a short note at the top explaining when you started on the code, and that you were using a different style, etc.
What would your answer be if the question were: Should you maintain the same shoddy workmanship when you are remodeling your home?
If you're fixing a broken wall tile in the bathroom, then it's not worth re-tiling the entire wall because they didn't use the right drywall.
When you're remodeling the kitchen, then you may correct the plumbing for that room or straighten out a bad floor. That's because it makes the rest of the job easier for you. And that's what it's all about, what kind of benefit does it give you verses the cost to you/your client.
You wouldn't rewire a lamp because it needed a new bulb.
If you're coding to a company-defined standard (or even just a team-defined standard), and the code that you're working on does not match the standard (or is so old that it doesn't match the current standard), then definitely clean up the code if you're going to be making major changes anyway. (As others have mentioned, do that to the baseline code, and check it in. Then check it out again and make the changes that you have to make to fix bugs, add features, etc.)

How to create a smart chat-bot? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I know that it's still an open problem so I don't expect to see complete answers here. I just want to find some approaches to solve the next problem:
I have a model (assume that is's bot's memory), and different words are associated with different objects in the model. Speaking with the bot is like executing sql-queries with a DB. Language is a very hard formalizable protocol. And we can't just write a million lines of code to implement some real language. But I believe that it's absolutely possible to implement some self-learning mechanism. How can it be implemented? Is it possible to implement learning "from scratch" or "from few basic words"? Just want to hear your ideas.
Actually, English is a very strict language and it's one of the easiest languages for experimenting with AI. Many other languages allow you to change the order of words (for example). And in some cases changed order can change the whole meaning or just add some intonation. I really don't have any ideas how to teach a bot for these things.
The first step, in taking this game to the next level, is ...
...to have a very clear view of prior art!
(and pardon me to say, the question doesn't suggest that you have such an extensive insight into the matter [and you're not alone, count me in ;-)])
Even, and maybe in particular, if your intention is to apply completely novel techniques and models, it seems important to review the literature on current and past practices. Aside from possibly identifying elements that may be adapted or reused in a new implementation, a survey of the domain will provide an keen understanding of the nature of the problem[s].
I've personally tried -on various and multiple occasions!- either the naive approach or the sophomoric approach to tackling broadly-defined problems. With the naive approach, one has but a very slight idea of the true nature and scope of the problem. The sophomoric sees us better equipped with domain knowledge and also with related tools, but this can also be misleading because without a deeper understanding, we tend to mis-read/mis-understand new material offered to us and also misuse some of the tools (a bit like the the fellow who's "good with a hammer" for whom many things look like a nail...)
It is particularly easy to make these mistakes in the field of NLP. That's because
Common sense seems to be all is required: after all a child, who's native tongue is English understands subtleties like
"He's not really an expert"
"He's really not an expert" (small wink at the OP's reference to the ordering of word in the English language)
We live in such exciting times, technology and knowledge wise: Processing power, programming language and tools, mathematical techniques, availability of affordable corpora... to name a few of these things that make this moment in time so special.
Far from me the idea of discouraging you in your chat-bot endeavor, I just hope that this long and generic exposé will encourage to look-before-you-leap, as this will truly save you time in the long run, I think in two ways:
provide you some frames of references (again, even if your intention is to "think outside these boxes")
maybe entice you to redefine the problem, for example by limiting it to particular domains of conversation (sports, or health, or life at a particular university campus...) or by focusing on a particular aspect of the problem (semantic awareness, smooth, natural sounding grammar, use of colloquial forms...)
Good luck ;-)
Check out MegaHAL's implementation for some ideas. We've used a variant of this bot for ages in an IRC channel of ours, and he does on occasion appear to be the intelligent mixture of many of our dominant personalities.
You "train" the bot -
each time the bot answer, you rank (or the tester) the answer - if the answer is good/logical - give high rank, if the answer is bad... low/negative rank.
use the ranking in the future to choose the answer, and this is how the bot learns...
There's a great description of Eliza in Paradigms of AI Programming. You should be able to implement a simple Eliza bot in a few days of work.
This isn't a learning algorithm, but it's surprising how realistic answers can be from something so simple.
You can create your own chat bot on BOT libre, http://www.botlibre.com.
The bots learns, can be trained, can be scripted, and your can program them, or let them program themselves.
Thew site supports embedding your bot on your own site, has REST API access, Android, IRC, Twitter. Free hosting, even for commercial bots.
AIML from the AliceBot project may help you out. It's a whole XML schema (if that doesn't put you off) for the branch of AI its concerned with.
An example from Wikipedia:
<category>
<pattern>WHAT IS YOUR NAME</pattern>
<template>My name is <bot name="name"/>.</template>
</category>
RebbeccaAIML is one quite well documented implementation.

How to type faster [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I've typed around 75wpm for the last few years but I've always wondered how people type +100wpm.
I've searched but I primarily find typing tutors that teach you to type.. not teach you to type faster. So far the only tip I've come across is to learn dvorak.
Are there exercises or tips to help break through the 75wpm wall?
I'm assuming Steve Yegge's recent post prompted this? The comments contain a number of tools and games for measurement and improvement, both online and off. I'll list them here:
Gnu Typist
TyperA
TypeRacer (Several people named this site)
Typespeed
typeonline.co.uk
Update: I just tried GNU Typist as per Mark Biek's suggestion, and I have to say that it seems like the best of the lot mentioned so far. It looks like there is a Windows version available, although I'm sure there are prettier (and more expensive) apps out there.
Setting yourself up in an ergonomic typing position is a good start. Take a look at the diagram here - notice the arms in a straight line, feet on the floor, etc.
In my experience most people tend to slow down when they get to unusual keys - numbers, symbols, punctuation, etc, so maybe some focused practice on those key combinations? practice typing out long strings of numbers and symbols, maybe try to use some Perl code as your copy-page :)
One of the things that helped me was something I learned from pianist... when doing a touch typing program, deliberately slow down and speed up your rate of typing from disgustingly slow to really fast in slow waves. This helps train yourself to figure out how to get your fingers to work together faster and reinforces the key locations.
Another one is perhaps a speed reading course might help? Generally your fingers are the last line of slow down in typing.
If you want to practice while having a little fun check out http://typeracer.com
It let's you compete against other people and trust me, there's nothing better to get you typing faster than normal than a little healthy competition.
Practice!
GNU Typist is a great, free, multi-platform program for practicing. They have different sets of exercises for practicing touch-typing as well as general Speed Drills.
Like a previous poster said, practice, practice, practice. But, if you are a developer (since you are on this site I assume that you are), then writing code will probably not be the type of practice that you need to improve your typing skills past your current maximum. I would even argue that 75wpm is more than adequate for any code writing task. But if you really want to practice more then I would recommend picking up a copy of Typing of the Dead
Consider switching to a keyboard layout that's designed for quick typing instead of just being layed out as it is for historical reasons, e.g. Dvorak or Colemak.
For me, it also helped a lot to use the caps lock key as backspace, for example using SharpKeys on Windows.
If you are really hardcore, create your own keyboard layout. On Windows, you can do that with the Microsoft Keyboard Layout Creator.
Chat. A lot.
I never received any touch-typing training. Infact, when i first started, i had to search the keyboard for the key... Now after 7 years of IMing, its all muscle memory. I have never tried to speed my typing, but a lot of times it just flows without me even realizing that i am typing as i think. Also i have noticed i can type in my usernames and phrases i often use a LOT faster than the other things.
This may or may not have been a useful answer.
Be careful, increasing your typing speed can increase the risk of carpal tunnel syndrome:
"The typing speed may affect risk, in some cases, however. For example, the fingers of typists whose speed is 60 words per minute exert up to 25 tons of pressure each day." [source]
Consistency and practice. Four things that improved my typing dramatically:
Find a comfortable keyboard that
fits your hands very well. It's less
about ergonomics or split keyboards,
but more about finding one with perfect finger reach. And this means using the keyboard for a couple weeks to see if it fits. Once you pick a keyboard, use it 100% of time. Have the same keyboard at home and work.
Make sure your workstation is
properly fitted to you. Basically, follow any decent ergonomics guide (90 degrees everywhere is WRONG!!!).
All of this "ergonomics" stuff has the benefit of stress on the rest
of your body that can distract you or cause muscle fatigue (i.e. slower typing). Again, use the same workstation configuration everywhere--if that means getting the same expensive chair at home, do it.
When emailing, chatting, and posting, use complete words and sentences. Abbreviations, slang, and other "shortcuts" taught me a lot of bad typing habits and made me lazy. They also had a lot of awkward letter combinations that didn't show up in other places, including normal composition and coding.
Consistency. Use the same tools with
the same settings and shortcuts all
the time. The less time you spend
worrying about how the software
works and reaching for the mouse,
the faster your typing will be.
You need to pick yourself up a copy of Typing of the Dead and start killing zombies. You'll be honing your typing skills and preparing for the eminent zombie apocalypse at the same time! Grab the demo to check it out!
In all seriousness, I've had this game for years and it really has helped me improve my typing skills and it's way more fun than any other typing program out there.
Type to the beat of a song. Start with a slow beat and work your way up. Don't rush it. Typing in bursts is often counter productive. Rhythm causes accuracy. The keyboard is just like a musical instrument and that's how musicians gain accuracy. You also need to practice regularly, even if just for 5 mins each day, to train your muscles.
I forget the details, but I remember the following was asked of some famous violinist:
"How did you learn to play so fast?"
His reply: "Really, really slowly".
:)
Use both hands (and all ten fingers).
To maximize your typing speed, you need to use the opposite pinky to shift/ctrl etc. and you want to minimize the amount of time you have to "reacquire" the home position. My biggest increase in typing when coding was to really learn my IDE's keyboard shortcuts, since that eliminated the relatively slow process of using the mouse.
Disable your mouse. (This is more for overall computer productivity than WPM.)
And I know you can't do it on your own, so get someone to enforce it.
It'll force you to learn keyboard shortcuts and consider keyboard-friendly options.
A nice, tactile keyboard helps. Especially if it's blank. You'll be speeding along in no time.
http://store.daskeyboard.net/prdaskeulorb.html
If you are having a problem with a particular key combo or miss-typing a particular word, or even just want to practice something, put it into your password. That way you get it fixed in your muscle memory as you can't even see what you are typing.
Practice, Practice and Practice
Make it so that you cannot see the keyboard, this will force your mind to remember where the keys are. I used this when starting on the Colemak keyboard layout and it worked really well.
The biggest way I increased my speed was by never looking down at the keyboard. I also have a very ergonomic keyboard that splits the keyboard in half so I get use to the right hand using the right side and the left hand using the left side.
My hands aren't my bottleneck, so touchtyping doesn't make me any faster. I already don't get enough bitrate out of my head to max out my hunt and peck. some people (me) may never be able to TT effectively.
agreed on muscle memory though. common thngs like usr/pass always get boshed out quickly without thinking, but for code, my hands are not the bottleneck
Get a Kinesis Essential keyboard. Keys are laid out better for faster typing.
IRC-ing a lot helpen a great deal with me;
Especially playing those Trivia like games where the fastest one gets the points.
You can also try "typespeed" on Linux.
If you really need more speed and you think you've mastered the technique you can also consider using the Dvorak keyboard layout; It will help you type fast but you really need to adapt to it.
I switched to Dvorak and my typing speed has increased, and I also learned after 8 years, how to touch type.
I would double the suggestion(s) to switch to an ergonomic typing position. Also, I've noticed that I cannot type faster on my laptop. I have an external anti-RSI QWERTY keyboard (with the reverse-V style key layout), and I can type a lot faster with more accuracy on that that I can on my laptop.
If you use a contoured keyboard, like, for instance, the Kinesis Advantage keyboard, it is easier to type blind, since it is much easier to feel where your hands are on the keyboard if it isn't flat. After a couple of days I was typing considerably faster than on a normal keyboard. And there is also a version switchable to Dvorak layout, though I never bothered to try that.
About blind typing: in my experience, knowing where your hands are is the important and difficult thing in blind typing - and after years of keyboard use you know very well where the common keys are. So just concentrating every once in a while to have your hands in the proper position for blind typing, and to type the keys with the right finger will get you into blind typing in a couple of months without any additional exercise.
(source: kinesis-ergo.com)

Resources