DEV Community

Cover image for What coding concept or practice seem commonly understood, but you never learned?
Ben Halpern
Ben Halpern Subscriber

Posted on

What coding concept or practice seem commonly understood, but you never learned?

Let's say you work independently and you get by, but maybe you're a little afraid that if someone were looking over your shoulder you might be exposed β€” even if you're a senior dev?

Top comments (78)

Collapse
 
sherrydays profile image
Sherry Day

git rebase β€” I barely understand how to use it, and really hope nothing goes wrong.

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€ • Edited

Imagine a literal tree 🌲 like that.

Now get a saw and cut a branch off

Next change the colour of the leaves of this branch to purple πŸ’œ

Next take your glue and climb up 🌲 the tree, and stick it right on the tip.

Where you cut the branch off, go there and paint some bark over it like it never happened but actually pretend it was always at the top

The base is the tree branch

You are re base ing the branch at the top of the tree, I think of it as magical time travel

Collapse
 
thumbone profile image
Bernd Wechner

Except that this picture explains nothing to me about what happens. It begs questions:

  1. What is a commit? Is it a diff? Or is it a whole copy of the repo?
  2. If it's a diff, how is rebasing it at the tip different to merging it there, I mean essentially it works fine if there are no conflicts if the diffs can automatically be applied without any ambiguity, but if not ... all the same merge issues arise.
  3. If it's not a diff, what does this rebase do to the tip and the (new) next commit. How do they relate, what's going on?

You see the confusion I (and I expect many) have around rebase is not the nice imagery of what it means (moving a branch somewhere else) it's the devil of the detail, about what happens to the changes between the point of divergence and the tip of both the branch being rebased and the place it's being rebased to.

Thread Thread
 
fjones profile image
FJones • Edited

For simplicity's sake, you can consider a commit a diff to the commit before it (called the "parent"). How git actually works under the hood is a fair bit more complicated (it actually stores blob data of specific states), but that's the surface-level workings.

When you merge, you're creating a new commit that applies the necessary changes to the two commits that are being merged together (the target branch's current commit, as well as the source branch's current commit). Here, again for simplicity's sake, you can consider that merge commit to be two diffs, one on either side, which produce the new merged state.

Rebase instead takes the diffs from the oldest divergence between the two branches, and moves them onto the current commit of the target branch. For that, it applies the same diff onto the current commit as its new parent (instead of whatever was the original parent), changing (ideally) only the parent relationship of the commit.

Thus, where a merge maintains two different routes which converge in the merge commit, the rebase maintains only one route to the same target state. This means that either of the merge commit's parents have their own parents until they reach back to the divergence, whereas the rebased branch only has a single line of parentage going first to the other branch's most-recent commit, which itself then has the parentage back to the original point of divergence (which is now no longer related to the rebased branch directly at all).

So where merge glues two sticks together in parallel, the rebase glues them together in sequence.

Edit: re what the actual differences are after-the-fact, operationally: if you go back to an earlier commit, it will only follow its own parent relationships. So if you check out a commit specifically on either of the merged branches, you won't have the changes from the other branch. As for conflicts, you do indeed get them either way, though rebase makes it a tad easier to ensure that an individual commit is consistent and can, for example, compile correctly for the expected state at the time. Rebase often cuts the conflicts into smaller chunks that are somewhat time-coded to the commit it is currently working on, before moving to the next in the rebase chain.

Thread Thread
 
adam_cyclones profile image
Adam Crockett πŸŒ€

I appreciate your wanting to get technical and I do see your point of view, but my little story is for people who have literally no idea what to think about rebasing, it's what I think about it and I do it all the time with no major fires for almost 5 years of rebasing πŸ”₯πŸš’πŸš¨. The details you crave and I suspect may know, are best learned / shown not told. Like can you describe an interactive rebase? It's not very easy on paper or in a comment text box ☺️

What I would say is that it offers a jumping off point to allow people to talk about things they would otherwise not know how to find the words

Thread Thread
 
adam_cyclones profile image
Adam Crockett πŸŒ€

Thanks for helping FJones!

Thread Thread
 
fjones profile image
FJones

Was slightly confused there for a minute, thought the other comment was directed at me :D

DEV still can't handle deep threads too well.

Thread Thread
 
adam_cyclones profile image
Adam Crockett πŸŒ€

It confuses me too 🀣

Collapse
 
erickgonzalez profile image
Erick

Love it. Thanks.

Thread Thread
 
adam_cyclones profile image
Adam Crockett πŸŒ€

Your most welcome, of course as it's been highlighted it's more complex than said but I think that's need to know

Collapse
 
spo0q profile image
spO0q πŸ’

The relevant usages are pretty rare and rebase can be risky, so, in doubt, not using it might be wiser.

It's not uncommon to set it as a global pull strategy (which is the same as git pull --rebase) to prevent useless merges of the same branch in the git history every time you pull the remote branch for updates (e.g., "merge master into master").

However, I would not recommend git rebase between different branches unless you perfectly know what you're doing (e.g. git rebase master develop). Otherwise, it can turn really nasty. I've already seen it, really hard to resolve.

I find the interactive rebase git rebase -i more helpful and less risky provided you use it only locally BEFORE pushing anything to the remote. It allows reorganizing and editing commits, which can improve readability.

Collapse
 
thumbone profile image
Bernd Wechner • Edited

I'm not sure anyone understands git rebase. Every single time someone mentions it I am back to the tutorial pages and it'll cost me some minutes of reading before, if I'm lucky I go "a ha, I think I get that".

Collapse
 
leob profile image
leob

Lol that's one I have to look up EVERY time to understand how it works again ... used it a few times, once it went horribly wrong, not using it anymore every since ... plain "git merge" is your friend!

Collapse
 
dinerdas profile image
Diner Das

Raise your hand if you only use print statements for debugging.

Debugging tools β€” not even once.

Collapse
 
ben profile image
Ben Halpern

raise hand

Collapse
 
marcello_h profile image
Marcelloh

I admit, I do use that from time to time, only if the "normal" way of debugging is out of the question. But a debugger can really be of help, if you can step through code you didn't write for example. Then you understand what flow the program does and why "x" is suddenly 4. or when you can immediately go to the function with line where the error occurred, and start your investigation from there.
(A stack-trace might be helpful too, and some debuggers do share this info with you)

Collapse
 
thumbone profile image
Bernd Wechner

Nah, browser debugging tools are your friend. Just plain awesome.

Collapse
 
shoeib_shargo profile image
Shoeib Shargo

Present, sir.

Collapse
 
anitpeter8 profile image
anitpeter8

glad i am not alone

Collapse
 
leob profile image
leob

For me that's only the case for Javascript debugging - any other language that I use, I don't have an issue using a debugger.

Collapse
 
calsch profile image
CalSch

🀚

Collapse
 
kayis profile image
K

Estimation 😭

Collapse
 
webbureaucrat profile image
webbureaucrat

He said "commonly understood" not "entirely impossible." πŸ™ƒ

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

I wouldn't worry too much about that. It's not worth doing, a total waste of time

Collapse
 
marcello_h profile image
Marcelloh

Yeah, like you want a house to be build and pay them by the day. How long is it going to take.
"we don't know" is not a valid answer. Estimation is very handy in order to start the process, or not.

Thread Thread
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

When was the last time you had a remotely reliable estimate from a builder? πŸ˜‚

Collapse
 
marcello_h profile image
Marcelloh • Edited

Estimation is always a bit of a challenge because you might need to do something you've never done before. So estimating that is based on your own experience.Which can be hard if you have never done something before. But based on what you have done can be helpful in finding out a rough estimation, which is of course better than saying that you don't know.

Look for known facts:
You (don't) know

  • the "surroundings"
  • similar parts
  • if it is done by others before
  • if it is complex

Give all of these a score. based on that score, give an estimation, but with the context why you came to that score / estimation.
If it still is hard, see if you can slice it into smaller pieces and do this piece by piece.
But in the end it's an estimation, right? So if you deliver in that time, should not be the question.
Also, estimate for yourself, if you have 10% or 25% ready. Then multiply that to a 100%. Keep track of the next 10% or 25% and see if you're still on schema. If not, tell and adjust your estimation. (and so it becomes more accurate in the end, but also along the way).
Good luck :-)

Collapse
 
booleanhunter profile image
Ashwin Hariharan • Edited

Oh, there's a lot of things I'd be uncomfortable with doing, if someone were looking over my shoulder:

  1. CSS: Not when I'm using a library, but when I'm using just regular CSS, especially when writing styles that are supposed to be pixel-perfect and responsive. I have considerably improved in CSS in the last one year but I'm still not confident enough.
  2. Regexes
  3. Doing a search on the CLI, especially when debugging server logs. Or using Bash terminal commands like tail, chmod, ps, grep etc

If someone is staring at my screen when I'm doing the above, the pressure to not make mistakes can be overwhelming. πŸ˜…

Collapse
 
ben profile image
Ben Halpern

Oh man, +1 on the CLI – my array of terminal commands is pretty limited.

Collapse
 
leob profile image
leob • Edited

Regex - beyond the really basic ones I have to look them up EVERY time - in practice when there's a simple way to do a task without a regex, I'll do so ...

Collapse
 
nishrico0098 profile image
Nishant Mishra

Totally Agree! Especially when it is your Nerd Sibling aka Brother/Sister

Collapse
 
ben profile image
Ben Halpern

Personally, having worked from home for years now β€” there are a lot of things you just only learn when in a physical space with people.

Collapse
 
leob profile image
leob

Examples?

Collapse
 
andypotts profile image
Andy Potts

How to make small talk

Collapse
 
matpk profile image
Matheus Adorni Dardenne

Dependency injection. It always rubbed me the wrong way.

Collapse
 
darthbob88 profile image
Raymond Price

Yeah, I understand the basic concept of passing dependencies in as a parameter, but the frameworks for doing that are always too magic for my taste.

Collapse
 
matpk profile image
Matheus Adorni Dardenne

Exactly how I feel. I know how to use it, but it feels............ wrong.

Collapse
 
marcello_h profile image
Marcelloh • Edited

it is a good way of not hard-wiring dependencies into parts of the code.
That code should work independently, which makes testing far less complex.

To explain it a bit more:
we want to travel so we take a vehicle to do that.
the vehicle should be able to steer, break and so on.
As a dependency, I give it a car to work with, and the vehicle is now a car and does satisfy its needs, but a plane, a truck, a bike etc. also can do that.
To actually test the software for "the break()" function, you can feed it a mocked-vehicle, that will help you in testing the behaviour. But you can also choose to have a "real" vehicle, up to you.

But if you wrote it by just accepting a car, then that's all it can work with.

Collapse
 
matpk profile image
Matheus Adorni Dardenne

SOLID, specifically the "L", implies that a function that requires a "vehicle" must work with cars, bikes, and planes without breaking the application. Dependency injection is not needed.

Collapse
 
drmikecrowe profile image
drmikecrowe

Amen

Collapse
 
kachidk profile image
Nwanguma Victor

same too

Collapse
 
auroratide profile image
Timothy Foster

Caching. When's it automatic, when do I invalidate it myself, why is this asset not refreshing, what are all these cache headers, something something redis??

Collapse
 
ben profile image
Ben Halpern

Oh man, caching is bad because every layer of the stack uses it in some way, so people use the same word to refer to a lot of different things happening.

It's a general-purpose computer science-y idea, so it would make sense that it's used in a lot of places, but then in web dev we generally mean very specific things in different contexts as well.

So yeah, it's a thing.

Collapse
 
warwait profile image
Parker Waiters

I installed a bunch of starter plug-ins in my editor when I first got started and haven't added another one since. I'm pretty sure I'm doing some stuff really unproductively. My flow works, but I'm pretty sure I'm doing it wrong.

Collapse
 
theaccordance profile image
Joe Mainwaring

The last time I encountered this type of question it was around 100% Code Coverage.

I had several years of exposures to tests but our team and products didn't fully embrace the strategy; I wasn't seeing the value in terms of code quality, rather just a check that what you wrote isn't broken upon a later revision.

After our company was acquired, the new engineering org embraced a standard of 100% code coverage. That is a very high bar, and we do allow exceptions, but overall the team has been able to meet that standard with ease.

With our projects having 100% code coverage, we saw improvements in Frequency of Deployments, Lead Time for Changes, MTTR, and Change Failure Rate (Read the book Accelerate if you're unfamiliar with these metrics), ultimately allowing us to build a product at scale - in terms of collaborators (~50 engineers) and deployment stability/consistency.

Collapse
 
marcello_h profile image
Marcelloh

Unfortunately, 100% code coverage doesn't say much if done the wrong way.
We aim as high as possible, but the complex code before the simple code.
And anything added should be covered by a test.

Collapse
 
theaccordance profile image
Joe Mainwaring

Read the book I reference in the original comment, if your engineering org adopts those practices, 100% code coverage makes a significant difference.

Thread Thread
 
marcello_h profile image
Marcelloh

Which book is that. Tried to find you book reference, but can't find it.
BTW: if we write a test for a simple getter (or for generated code for that matter), that will be the day that all other significant tests are written :-)

Thread Thread
 
theaccordance profile image
Joe Mainwaring

Accelerate

Collapse
 
hassnainabass profile image
Hassnain Abass • Edited

redux in react

Collapse
 
jensmou profile image
Jens Mouridtsen

All the files needed is confusing indeed. Take a look at Redux Toolkit. I find it much simpler to use. Still not super easy, but better.

Collapse
 
odysseaspapadimas profile image
Odysseas Papadimas

Most of the time I find the Context API to be enough. That said I used Redux Toolkit once and it was pretty cool