‹ Sid Verma

Tags / Programming

Page 3


This post might seem like nitpicking, or unnecessary to a lot of people, but it’s frustrating when links don’t work how they’re expected to.

  • DO NOT use <span> or <div> tags and then proceed to handle their click events. Use proper <a> tags. This breaks so many things!

    • People can’t use them if they have disabled javascript or it just failed to load.
    • Ctrl-click will not open a new tab unless you explicitly handle the situation. (More on that below)
    • Even then, you just dumbed down your users’ context menus. No Open link in new tab, or Copy link address.
    • The same situation on mobile. Long click will copy the text instead of showing helpful actions.
    • The javascript might break, throw an unexpected error, or burn down your house, rendering that “link” useless.
  • Even when you are using <a> tags:

    • If possible, execute whatever JS you want, and then let the link do its job. Don’t preventDefault() and open the link through javascript.
    • If you really have to open it through JS, take care of Ctrl-clicks. And Cmd-clicks in case of macOs. Old browsers might make this difficult.
  • Put mailto: links only where the email-id is the visible text too. [email protected] is so much better than Contact Email. Not everyone has email clients configured, and opening bulky clients when clicking a link is just bad UX. Or people might just want to note down the address, to contact later.

I love Sublime Text. I really do. I can put a ring on it if it had any corporeal form. I’ve been using it so much, that trying to work on anything else is kind of a pain. And yet, when dealing with STDIN inputs, the magic falters. This method describes a workaround to give inputs without a prompt.

Recently, I tried my hand on Competitive Programming, and though I didn’t get really good at it, I did encounter a frustation. Entering the same input again and again after every change I make to the code. I wanted a simpler method.

Here’s what a friend of mine came up with: Enter the input in comments.

/*input
2
foo
bar
*/

#include <stdio.h>
int main() {
  int n,i;
  char s[10];
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s",s);
    printf("%s\n",s);
} }

gives the output:

foo
bar
« Older posts Newer posts »