I want to share some programming tips based on my experience to everyone. But I don't know where to start since they relate to Opinion-based
questions.
Example with javascript:
Normally, there are some ways to create a bootstrap dropdown manually using jquery:
var icon = $('<i class="fas fa-ellipsis-h">');
var button = $('<a href="#" data-toggle="dropdown">');
button.append(icon);
var item = $('<a class="dropdown-item" href="#">');
item.text('Option 1');
var menu = $('<div class="dropdown-menu">');
menu.append(item);
var dropdown = $('<div class="dropdown">');
dropdown.append(button).append(menu);
1000 years later, you may want to say it's hard to maintain or update when the template is getting changes.
What's happen with the names if:
There are more than 1
icon
.There is some nested menu inside the
menu
.We want to replace the icon with a text link.
...
And, how does it look like if we need a lot of <div>
tags which contain float-left
, float-right
, d-table
css styles?
var floatLeft = $('<div class="float-left">');
var floatRight = $('<div class="float-right">');
var dTable = $('<div class="d-table">');
It's awful.
To avoid that troubles, I recommend to use this:...
Question
So: Where or how would I post this on Stack Overflow? Or is the Q/A format the only way we can share knowledge?
Edit: My post is different from May I ask for tips? because I don't require any review for my code. Just share some ways to let everyone reviews their own code.