Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "string.format"
-
logger.info(String.Format(" User {0} changed their password from {1} to {2}", username, oldPassword, newPassword))
Production system. Plaintext log.10 -
Karma...you're the best.
An ex-team member was complaining to me about his manager reviewing his code. Shortened version of the convo:
Mgr: "Why didn't you use the new C# built-in extension methods?"
Dev: "No reason. I thought using the straight forward approach would be easier to maintain"
Ha!..you conceded, arrogant mother <bleep>er. How many times did I have to listen you berate other developers in code reviews for not using some random C# syntax sugar? Comments like "If you bothered to read the new C# 7.0 language specification like I did...you would have known not to use the string.Format anymore..."
Now you're pissed that the manager embarrassed you? How does it feel d-bag?
That's too evil...so I simply responded "I don't think Nick meant anything negative about your code, he's just trying to help."
Seeing him stir around all pissed off does make me giggle like a little schoolgirl.7 -
String username = "Xx_thelegend27_xX";
final Pattern pattern = Pattern.compile("(xx|(_|))(?<username>\\w*)(_|(xx))", Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(username);
if(matcher.matches()){
this.showError(String.format("Your username cannot be that... Try: %s", matcher.group("username")));
}else {
registerOrSomething();
}2 -
When coworkers leave the co. for a better paying job and leave this kind of code after themselves:
int foo = 1;
String.format("blabla %s", Integer.toString(foo));
fml6 -
Started a new job as junior developer. One of my first task was to sent a simple notification on an event in out product. Write the code, test that it works, push to devops.
Code compiles, tests pass, it’s deployed to internal test env. Check that my notification works in the test env. No problem.
It’s deployed to the customers test environment. It works and customer accepts it for prod.
We release to prod and of course it fails. Seems to be a simple string.Format that fails for god knows why. After 3h of debugging on prod without success we decide to roll it back.
Today we decided to try it on a backup of the prod db since one of the strings was taken from the db. Still working. No matter what data I input when trying it locally it still wont reproduce the issue we saw on prod.
Fuck this6 -
Today my boss sent me something that smelled fishy to me. While he was trying to simulate Excel's rounding he faced what was to him unexpected behaviour and he claimed that one constructor of the BigDecimal class was "wrong".
It took me a moment why this was happening to him and I identified two issues in his code.
I found one fo the issues funny and I would like to present you a challenge. Can you find a number that disproves his claim?
It's Java if anyone was wondering.
double d = 102.15250;
BigDecimal db = new BigDecimal(d)
.setScale(3, BigDecimal.ROUND_HALF_EVEN);
BigDecimal db2 = new BigDecimal(String.format("%f",d))
.setScale(3, BigDecimal.ROUND_HALF_EVEN);
BigDecimal db3 = BigDecimal.valueOf(d)
.setScale(3, BigDecimal.ROUND_HALF_EVEN);
System.out.println(db); // WRONG! 102.153
System.out.println(db2); // RIGHT! 102.152
System.out.println(db3); // RIGHT! 102.152
P.s. of course the code itself is just a simple check, it's not how he usually writes code.
P.p.s. it's all about the numerical representation types.8 -
var peanutButter = “creamy”;
var jelly = “strawberry”;
var bread = “Wonder”;
public string Lunch(peanutButter, jelly, bread, out satiation)
{
int stomach = 0;
string mouth = “”;
for (int hunger = 100; hunger > stomach; hunger--)
{
mouth += String.Format(peanutButter + jelly + bread);
stomach++;
}
return var satiation = “YAAASSSS”;
};4 -
Can anybody explain why in C# when using string.Format("{0:C}", myNumber);
results in a string with special characters used for spacing instead of the normal space character.
This caused a issues in the PDF I was generating and I'm wondering why the special characters.4 -
WHAT IS WRONG?
public class Person {
String name;
public Person (String personName) {
name = personName;
}
public String greet (String yourName ) {
return String.format ("Hi %s, my name is %s" + name+yourName);
}
}3