What is the best way to type ()? [closed] - typing

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
This might not be exactly a programming question but it is related to programmers so if anyone knows the answer it will be someone here.
I have started suffering from some kind of RSI because of the way I type parenthesis and I was wondering what the best way to type them is without straining my wrist.
I currently type ( ) or _ by pressing Shift(Right) with my fourth finger (right hand) and then swivelling my wrist and flattening out my palm so that i can simultanesouly press one of the mentioned symbols with my index(trigger) finger.
Correction method or good links will be appreciated.

I use my left ring finger (or the one between middle and little) to push left shift and then right middle finger for parantheses. It's much easier than trying to stretch from right shift to 9/0.
It doesn't matter; why not just use the left shift?

In touch-typing courses I was always taught to use the opposite hand to use the shift key. Thus for your example, I'd use my left pinky to hit the left shift key, then hit the (, ), or _ keys. It saves on strain.

I press shift with my left pinky and then the ( key with my right middle finger and the ) with my right ring finger. This is how I learned to do it back in the day and it's stuck. Hope it helps.

Never thought about it.. I still type with two fingers, I can just do it quickly!
I use my little/pinky finger on right shift and the one next to my thumb on the number key. Its comfortable enough.
Get bigger hands or a smaller keyboard perhaps? Or, use left shift so you don't have to strain :-)

Use an ergo keyboard. The MS natural 4000 allows for the right handed shift-9/0 with a minimum of discomfort. It also includes specific peren keys above the number pad.

Related

In accordance with Missy Elliott's song Work It, what data structures can be both flipped AND reversed? [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 1 year ago.
Improve this question
In Missy Elliott's song Work It, she sings, "I put my thang down, flip it, and reverse it."
A lot of jokes have been made of these lyrics, including this classic xkcd: https://xkcd.com/153/
I recently saw this tweet, https://i.imgur.com/wFmIaEE.jpg , and began to wonder what data structures can be flipped AND reversed.
A linked list can be reversed, but can it be flipped?
A B tree could be 'flipped' in the sense that child nodes point to parent nodes instead of the other way around but I would probably describe this as 'inverted' not flipped.
I think an array could be flipped by swapping its indices and values. Could it then be reversed?
The written lyrics are:
I put my thang down, flip it and reverse it
Ti esrever dna ti pilf nwod gnaht ym tup i
This line is definitely reversed, but I don't think it's flipped. I think if the characters were upside down, then they would be both reversed AND flipped.
I'm looking for a serious answer as I hope this could lead to a fun interview question.
Not so easy, since presumably you want flipping and reversing to be distinct operations so that you don't end up with the same structure. Also you want them both to be real operations, not just drawing differently.
The only thing that comes to mind is this recent SO question, where I mention that a postorder traversal of a tree is the reverse of the preorder traversal of the reversed tree: Uniqueness of Inorder, Preorder, and Postorder traversal with null elements
So... if you want to convert a pre-order traversal function to post order or vice-versa, you can whack the tree down, flip it around and then reverse the output.
A function that converts a pre-order traversal function into a post-order traversal function would be the Missy Elliott Combinator, which is not a bad name at all.
ETA:
Also, and completely unrelated...
You can perform any rotation of an object in 2D by reflecting it across a chosen line (the flip) and then reversing it along an axis. The angle of rotation is twice the angle between the lines of reflection. It also works for pointing an object along any vector in 3D.
This operation should obviously be known as a Missy Eliott rotation.

What are a few tips for optimizing go (golang) code when using slices (or arrays) of bytes? [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 8 years ago.
Improve this question
I waw wondering what could be some of the common pitfalls that a novice go programmer could fall in when writing (unintentionally slow go code).
1) First, I know that in python doing string concatenation can be (or used to be expensive), is that the same in go when trying to add one element to a string? As in "hello"+"World".
2) The other issue is that I find myself very often having to extend my slice with a list of more bytes (rather than 1 byte at a time). I have a "dirty" way of appending it by doing the following:
newStr := string(arrayOfBytes) + string(newBytesToAppend)
Is that way slower than just doing something like?
for _, b := range newBytesToAppend{
arrayOfBytes = append(arrayOfBytes, b)
}
Or is there a better way to append whole slices to other slices or maybe a built in way? It just seems to me a little odd that I would even have to write my own extend function (or even benchmark it)
Also, sometimes I end up having to loop through every element of the byte slice and for readability, I change the type of that current byte to a string. As in:
for _, b := range newBytesToAppend{
c := string(b)
//some more logic on c
logic(c) //logic
}
3) I was wondering, if converting types in go is expensive (specially between string to arrays) and if that might be one of the factors that might be making the code slow. Btw, sometimes I change types (to strings) very often, nearly every iteration.
But more generally, I was trying to search for the web a list of hints of what often are things that makes go code slow and was trying to change it so that it wouldn't (but didn't have that much luck). I am very much aware that this depends from application to application, but was wondering if there are any "expert" advice on what usually makes "novice" go code slow.
4) The last thing I can think of is, that sometimes I do know in advance the length of the slice, so I could just use arrays with fixed length. Could that change anything?
5) I have also made my own types as in:
type Num int
or
type Name string
Do those hinder performance?
6) Is there a general list of heuristic to watch out in go for code optimization? For example, is dereferencing a problem as it can be in C?
Use bytes.Buffer / Buffer.Write, it handles re-sizing the internal slice for you and it's by far the most effiecent way to manage multiple []bytes.
About the 2nd question, it's rather easy to answer that using a simple benchmark.

Are trailing commas in Perl a bad practice? [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 6 years ago.
Improve this question
Today I was in a Webex meeting showing my screen with some Perl code I wrote. My boss suddenly told me while everyone else was looking and hearing that I had to remove trailing commas from my hash and array structures because it is a bad practice. I said I didn't think that was a bad practice in Perl, but he insisted and made me delete those commas just to show my script running in the meeting.
I still think it's not a bad practice in Perl, but I can be wrong. I actually find them pretty convenient and a good practice because they prevent me from adding new elements and forgetting to add the corresponding comma in the process.
But, I'd really like to know if it's a good or bad practice and be able to show it my boss (if he's wrong) with good arguments and even good sources for my arguments.
So, is it a bad practice to leave trailing commas?
This is an example:
my $hash_ref = {
key1 => 'a',
key2 => 'b',
key3 => 'c',
};
my $array_ref = [
1,
2,
3,
];
It's a great practice to have the trailing comma. Larry added it because he saw programmers add elements to a list (or whatever their language called it) but forget the separator character. Perl allows the trailing comma to make that less common. It's not a quirk or side effect of something else. That's what Perl wants you to do.
What is bad practice, however, is distracting a meeting full of people with something your boss could have corrected later. Unless the meeting was specifically a code review, your boss wasted a bunch of time. I've always wished that to join a video conference, you had to enter your per-minute compensation so a counter would show on everyone's screen to show how much money was being wasted. Spending a couple hundred dollars watching you remove commas on a working program would tamp down that nonsense.
So the PBP page referred to by Miller argues for making it easier to reorder the list by cutting and pasting lines; the mod_perl coding style document linked by Borodin argues for avoiding a momentary syntax error when you add stuff.
Much more significant than either, in my opinion, is that if you always have a trailing comma and you add a line, the diff only shows the line you added and the existing lines remain unchanged. This makes blame-finding better, and makes diffs more readable.
All three are good reasons for always using trailing commas, and there are in my opinion no good reasons not to do so.
The Apache mod_perl coding style document says this
Whenever you create a list or an array, always add a comma after the last item. The reason for doing this is that it's highly probable that new items will be appended to the end of the list in the future. If the comma is missing and this isn't noticed, there will be an error.
What your manager may have been thinking of is that doing the same thing in C is non-standard and non-portable, however there is no excuse for his extraordinary behaviour.
It is indeed a good practice and also mentioned in the famous PBP.
There is actually a Policy for perlcritic which always gets me: https://metacpan.org/pod/Perl::Critic::Policy::CodeLayout::RequireTrailingCommas
I favor leading commas, though I know its rather unpopular and seems to irritate the dyslexic. I also haven't been able to find a perltidy option for it. It fixes the line-change-diff problem as well (except for the first line, but that's not usually the one being changed in my experience), and I adore the way the commas line up in neat columns. It also works in languages that are white-space agnostic but don't like trailing commas on lists quite neatly. I think I learned this pattern while working with javascript...
my $hash_ref =
{ key1 => 'a'
, key2 => 'b'
, key3 => 'c'
};
my $array_ref =
[ 1
, 2
, 3
];

Which are admissible heuristics and why? [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 10 years ago.
Improve this question
There are n vehicles on an n x n grid. At the start they are ordered in the top row 1. The vehicles have to get to the bottom row such that the vehicle at (1,n) must get to (n, n − i + 1). On each time step, each of the vehicles can move one square up, down, left or right, or it can stay put. If the vehicle stays put, one adjacent vehicle (but not more than one) can hop over it. Two vehicles cannot occupy the same square.
Which of the following heuristics are admissible for the problem of moving all the vehicles to their destination?
i. sum from 1 to n (h1 ... hn)
ii. max(h1 ... hn)
iii. min(h1 ...hn)
I think that iii is the only correct one, but I'm not sure how to formulate my reasoning on why.
I am sure someone will come along with a very detailed answer, but as a favour to those who like me can be a bit overwhelmed by all things AI, an admissible heuristic is quite simply:
A heuristic that never overestimates the true cost of getting to the goal
Not to sound too uncharitable, but it sounds as if maybe the problems you've posted are from a homework problem or assignment. I wouldn't want to spoil your fun working out exactly which of those three heuristics are and aren't admissible - but hopefully that one sentence definition should help you along.
If you get confused, just remember: if once your vehicles have both reached their goals you find the actual cost was less than what the heuristic thought it would be then it's inadmissable.

lecture slide about AI [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 10 years ago.
Improve this question
Below is a lecture slide about AI. I think it's a pseudo code about something.
But I don't know what these symbols mean. I even can't get the main points of this slide.
Please help me. Thank you :)
It's not pseudocode. Please check out Norvig and Russell, "Artificial Intelligence: A Modern Approach". This looks like effects of an action for a reflex agent but you need at least the previous slide and probably the previous few slides to determine that. It could also deal with the frame problem in some way.
At any rate, presumably given an action with a precondition p and an effect e and a state s, the set of effects are the four logic statements: x , not x, x and not x. The first two logic statements say x when x has the value 1 in the effect e, etc. The third and fourth logic statements say x if in the set of logic clauses phi then x has the value 1 in effect e and the state s entails (|=) the set of logic clauses phi.
So a pair precondition,effect is executable in a state s if and only if s entails p and the set of effects in s is consistent.
But as I said more information is actually needed.

Resources