This is a weekly roundup of awesome DEV comments that you may have missed. You are welcome and encouraged to boost posts and comments yourself using the #bestofdev tag.
Timebox yourself. At work I drudge through 10y/o legacy code, so I get into this situation from time to time. Typically I’ll give myself x amount of time to look at a problem from one angle before stepping back to think of any other solutions.
I use spaces because I stick to conventions, but I would prefer tabs because:
- That the purpose of tabs.
- Count as one character.
- Accessibility: IDEs can display tabs with selected width.
I read a post about a guy with a severe sight issue, who, to be able to code, had a very large font size configured in his IDE.
But at this font size, four spaces are huge, and he had to scroll horizontally all the time.
So each time he edited a file, he changed spaces to tabs (which were displayed with a width of one space), and changed back tabs to spaces before to commit !
For most of us, the battle of tabs vs spaces is totally vain.
For some of us, it can change their everyday experience.
The simple explanation is that each commit in
git has one or more 'parents', which are commits that come logically before it in the change history, and
git rebase changes what the parent of the base commit (that is, the commit that you started the branch from) in a branch is. Essentially, if you think of each commit as a folder in the filesystem, it's parent is the folder that contains it, and
git rebase is equivalent to moving it into a different folder (of course, with lots of extra stuff to sanely handle conflicts).
This is useful for a number of things:
- Assuming you have a branch B based on another branch A, it lets you update B to include changes from A without needing a merge commit. This usually results in history that much is easier to understand than if you had merged A into B to do the same update. The general syntax for this is
git rebase A B(or, if you have branch B checked out,
git rebase A). In many workflows, this is the preferred way of updating branches that you have not published anywhere because it helps keep the history simple. This is about 95% of what most people will ever need
- Assuming you have a branch C based on a branch B but need it to be based on a different branch A, it lets you transplant branch C so that it's based on branch A instead of branch B. This is useful when you accidentally start a branch from the wrong base. The general syntax for this is
git rebase --onto A B C. This covers a significant majority of the remaining 5% of what most people will ever need it for.
git rebasecan take tags or even commits instead of branch names, you can use it to move individual commits or sequences of consecutive commits from one branch to another with the
git rebase --ontosyntax. This is useful when you end up developing a fix for an existing bug as part of developing a new feature, and need to submit that fix separately from the new feature. Note however that
git cherry-pickplus a carefully crafted
git resetis often preferred here, as it's a lot easier to get right than doing the same thing with
git rebase --onto(and it's usually easier to fix if you get it wrong).
- Similarly because of the fact that it accepts commits or tags, you can use
git rebaseto remove a series of commits from further back in the history of a branch using the
git rebase --ontosyntax. This is not something that is frequently needed if you're doing your development work properly, but if you haven't published a branch yet, this may be preferable to reverting a prior commit in the branch as it will make the history more concise.
- Aside from the above, you can perform arbitrary transformations to the history of a branch by doing an interactive rebase (
git rebase -i, also works with the the
--ontosyntax, though that tends to be very confusing so it's generally not the best idea to do it in one step (you can always
git rebase -iand then
git rebase --ontoas two separate steps)). This is only very rarely needed in a vast majority of development workflows (especially if you're doing your development work right), but it lets you do very complex things like splitting a commit into multiple commits, merging a bunch of commits into one, reordering the commits on the branch, or even just running a given command in the working tree for each commit on the branch (useful for testing proper bisectability of a sequence of changes, which is a major reason that
git rebase -iexists in the first place).
There is, however, one very big caveat to using
git rebase. Because it modifies history, you have to use a force push whenever you rebase a branch and then have to update a remote copy of that branch. This plus the rewritten history makes it very difficult for others to update copies of that branch in any clones of the repository (it requires them to delete their local copy of the branch, re-fetch the refs for it from the remote, and then check it out again), especially if they have any local work based on it. As a result, the general advice is to avoid rebasing any published branches outside of situations that you've agreed with your coworkers that it's acceptable to do so.
You may also want to look at
git cherry-pick, which lets you copy commits from one place to another (unlike
git rebase, which functionally moves commits).
I have a repo in progress for this. Anyone can PR additions!
Coding Resources For Kids
This list contains English resources for pre-school and elementary school aged children to learn coding either online or via native apps.
Pre-School - Grade 1
No reading or only very basic reading required.
Lightbot App. $3
- By SpriteBox LLC.
- Android & iOS.
Algorithm City Pro App. $2
- By Musteren.
CodeSpark Academy & The Foos. $7.99/m
- Android & iOS.
- Best on tablets.
Code.org - CS Fundamentals (grades K-5). Free
- Pre-Reader Courses A & B (K & Grade 1).
CodeSpark Academy & The Foos - codespark.com/. $7.99/m
- App also available.
- No reading required.
Kodable Youtube Videos. Free
Grade 2 - 3
Light reading skills required.
Code.org - CS Fundamentals (grades K-5). Free.
- Pre-Reader Courses C & D 2018.
- Pre-Reader Courses E & F.
- MineCraft Hour Of Code - code.org/minecraft (grades 2+).
Someone on Twitter once summarized it along these lines and I've been using this to teach status codes for a while now:
1xx: I thought you should know
2xx: All good
3xx: Look somewhere else
4xx: You messed up
5xx: We messed up
See you next week for more great comments ✌