war crimes in programming - A thread to discuss and share horrifying programming ideas/code

  • 🔧 Site instability resolved. You can report double-posts and broken attachments. For bigger issues, use the Technical Grievances thread.
    🇵🇦 Nuestro primer dominio localizado está en español en kiwifarms.pa. Our first localized domain is on Spanish on kiwifarms.pa.
  • Want to keep track of this thread?
    Accounts can bookmark posts, watch threads for updates, and jump back to where you stopped reading.
    Create account
C++:
void QImprovedSlider::mousePressEvent(QMouseEvent *event) {
  QStyleOptionSlider opt;
  initStyleOption(&opt);
  QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);

  if (event->button() == Qt::LeftButton &&
      !sr.contains(event->pos())) {
    int newVal;
    if (orientation() == Qt::Vertical) {
       double halfHandleHeight = (0.5 * sr.height()) + 0.5;
       int adaptedPosY = height() - event->y();
       if ( adaptedPosY < halfHandleHeight )
             adaptedPosY = halfHandleHeight;
       if ( adaptedPosY > height() - halfHandleHeight )
             adaptedPosY = height() - halfHandleHeight;
       double newHeight = (height() - halfHandleHeight) - halfHandleHeight;
       double normalizedPosition = (adaptedPosY - halfHandleHeight)  / newHeight ;

       newVal = minimum() + (maximum()-minimum()) * normalizedPosition;
    } else {
        double halfHandleWidth = (0.5 * sr.width()) + 0.5;
        int adaptedPosX = event->x();
        if ( adaptedPosX < halfHandleWidth )
              adaptedPosX = halfHandleWidth;
        if ( adaptedPosX > width() - halfHandleWidth )
              adaptedPosX = width() - halfHandleWidth;
        double newWidth = (width() - halfHandleWidth) - halfHandleWidth;
        double normalizedPosition = (adaptedPosX - halfHandleWidth)  / newWidth ;

        newVal = minimum() + ((maximum()-minimum()) * normalizedPosition);
    }

    if (invertedAppearance())
        this->setValue( maximum() - newVal );
    else
        this->setValue(newVal);

    event->accept();
  }
  else {
        QSlider::mousePressEvent(event);
  }
  emit onClick(this->value());
}
Things I would like to point out
C++:
double halfHandleHeight = (0.5 * sr.height()) + 0.5;
Unnecessary use of parentheses. Order of operations will already give the right answer. Adding parentheses when they are not needed makes it look like the programmer lacks basic math ability.

Use of types seems poorly thought out. setValue takes an int so the use of double is poor because the only use for it is to have fractions when calculating the step size and applying it, but it's not used consistently enough. Again, shows poor understanding of semantics.

It's also very redundant. The same procedure is implemented twice almost verbatim.
 
Unnecessary use of parentheses. Order of operations will already give the right answer. Adding parentheses when they are not needed makes it look like the programmer lacks basic math ability.
hello this is the lisp internet defense force
this post has been fact checked by independent s-expression experts: (post-fact-check *nigger-above-me*) => 'incredibly-false
you should kill yourself immediately

to be serious, using a lisp number of parentheses in non-lisp code can get stupid sometimes
...but not here. i honestly think this use of parentheses, while redundant, is not a problem at all.
It's also very redundant. The same procedure is implemented twice almost verbatim.
that's the biggest problem
and the fact that he uses a gnarly maze of intermediate variables and mutations to make the code completely incomprehensible
 
Atrás
Top Abajo