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 - "tostring"
-
Yesterday: Senior dev messages out a screenshot of someone using an extension method I wrote (he didn’t know I wrote it)..
SeniorDev: “OMG…that has to be the stupidest thing I ever saw.”
Me: “Stupid? Why?”
SeniorDev: “Why are they having to check the value from the database to see if it’s DBNull and if it is, return null. The database value is already null. So stupid.”
Me: “DBNull is not null, it has a value. When you call the .ToString, it returns an empty string.”
SeniorDev: ”No it doesn’t, it returns null.”
<oh no he didn’t….the smack down begins>
Me: “Really? Are you sure?”
SeniorDev: “Yes! And if the developer bothered to write any unit tests, he would have known.”
Me: “Unit tests? Why do you assume there aren’t any unit tests? Did you look?”
<at this moment, couple other devs take off their head phones and turn around>
SeniorDev:”Well…uh…I just assumed there aren’t because this is an obvious use case. If there was a test, it would have failed.”
Me: “Well, let’s take a look..”
<open up the test project…navigate to the specific use case>
Me: “Yep, there it is. DBNull.Value.ToString does not return a Null value.”
SeniorDev: “Huh? Must be a new feature of C#. Anyway, if the developers wrote their code correctly, they wouldn’t have to use those extension methods. It’s a mess.”
<trying really hard not drop the F-Bomb or two>
Me: “Couple of years ago the DBAs changed the data access standard so any nullable values would always default to null. So no empty strings, zeros, negative values to indicate a non-value. Downside was now the developers couldn’t assume the value returned the expected data type. What they ended up writing was a lot of code to check the value if it was DBNull. Lots of variations of ‘if …’ , ternary operators, some creative lamda expressions, which led to unexpected behavior in the user interface. Developers blamed the DBAs, DBAs blamed the developers. Remember, Tom and DBA-Sam almost got into a fist fight over it.”
SeniorDev: “Oh…yea…but that’s a management problem, not a programming problem.”
Me: “Probably, but since the developers starting using the extension methods, bug tickets related to mis-matched data has nearly disappeared. When was the last time you saw DBA-Sam complain about the developers?”
SeniorDev: “I guess not for a while, but it’s still no excuse.”
Me: “Excuse? Excuse for what?”
<couple of awkward seconds of silence>
SeniorDev: “Hey, did you guys see the video of the guy punching the kangaroo? It’s hilarious…here, check this out.. ”
Pin shoulders the mat…1 2 3….I win.6 -
Code: if(customer.primaryContract)
Boss: "just using a variable as a boolean isn't very readable"
Me:
if(!(!customer.primaryContract != !true).toString() == 'false')13 -
Watching a tutorial.
* Uses the mouse in order to select and format code, instead of the shortcuts VS code provides
* Does multiple "bool == true"-comparisons
* Doesn't use string interpolation and makes unnecessary .toString() calls
* Adds fucking parentheses around the whole fucking expression he wants to assign
value = (expression)
* Explanations so vague, the EU wants to hire him to reform the internet
Fucking waste of time even on x2.25 speed.10 -
So I'm cleaning up some buggy Java code when suddenly this dandy fine line appears:
if (new Double(a).toString() == "1.3") ...
Someone got paid for this :|10 -
To all the programmers calling “ToString()” on variables that are already of type String....
Please stop.22 -
condition == true
is for boys,
public static boolean isTrue(boolean condition) {
try {
return new Boolean(condition).equals(Boolean.parseBoolean(new String(Boolean.toString((boolean) Boolean.class.getField(String.valueOf(true != false).toUpperCase()).get(null)).toString().toCharArray())));
} catch(Throwable t) {
return condition;
}
}
is for men.6 -
While working on my one of the first project in java i ended up using deprecated Calendar API for the date. Since deadline was near i thought it would be a good idea to use the JCalendar API for as date picker (which is a third party API).BAD IDEA. It was the night before the submission round about 11pm when i realized that there is no way to convert JCal object into Calendar and it turned out it is not working as expected you have to subtract a particular number from the year to get date right.
To convert JCal into Calendar i used the toString function to get the date in string sliced it using substring into year,month,day then had to assign date to Calendar object via constructor.
Had to write 70 lines of code just to convert JCal into Calendar...
And then there were other complications related to this problem. Had tu pull an all nighter just to solve date related problems
LESSONS LEARNED :
NEVER USE A DEPRECATED API
NEVER USE THIRD PARTY APIs WITHOUT RESEARCH7 -
( true && false ).toString() + "rant"
49 20 6A 75 73 74 20 6C 65 61 72 6E 65 64 20 74 6F 20 73 70 65 61 6B 20 69 6E 20 68 65 78 20 6C 61 6E 67 75 61 67 65 2E 20 55 54 46 2D 38 20 69 73 20 74 68 65 20 6D 6F 73 74 20 73 70 6F 6B 65 6E 20 64 69 61 6C 65 63 74 2E 20 57 68 69 63 68 20 64 69 61 6C 65 63 74 73 20 64 6F 20 79 6F 75 20 75 73 65 20 6D 6F 73 74 3F5 -
I sincerely like the moment, when i train a newbie to code .NET showing him/her how far OOP in .NET goes.
I love to give the following example:
var s = "round and round it goes";
s = s.ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString();
And yeah. It's totally fine.
Because each component of .NET is inherited of object. And the class object supports you with the function "ToString()".
After that, in most of the cases, i get a slightly irritated look from the newbie.
Than i say, "welcome to Microsoft" ;)
I finally add, that the compiler of .NET finally identifies duplicate results and refactores the given code before execution ^^
Coding Is fun, as long as you get the big picture/concept of the language you're using.2 -
Why the fuck do people learn a framework if they don't even know the fucking most basic knowledge about the language.
Every fucking JS dev should know what the fucking toString result of a function object is! Thats like second page JS book stuff.
Even for Facebook groups this is a horrible question.5 -
Any malware specialists here?
Yesterday I started dismantling the virus that is spreading on facebook messenger these days.
What techniques do you use? Any special trick that doesn't require years of practice and could make my job easier? I have already familiarized myself with the nicifier and Function.ToString() traps. Now I have an 850 line JS file full of weird code and I have deciphered like 70 lines so far so I'm looking for some tool, strategy or algorithm to make my job easier.10 -
So, learning Java at the moment.
Thoughts so far:
“This IDE is going to make me so lazy! It can write getters, setters, AND toString() for me?!”
“Oh my god, angle brackets. It’s like someone with a love of nesting was made fun of for wasting space and retaliated by crafting a language that inlined nesting data types.”
“Whoa, this would safeguard what kind of input went into the function SO MUCH.”
“DOES THIS MAKE IT EASIER TO WRITE UNIT TESTS?! *excited*14 -
var a = {
value: -1,
toString: function() {
return ++this.value;
}
}
if(a & !a) {
console.log("F**k you JS!");
}
if(a == 2 && a == 3) {
console.log("F**k you again JS!");
}6 -
I don't judge whoever wrote this line in one of the projects I've been working on
return 0.ToString()
Like, really, there has to be a LOGICAL, and REASONABLE explanation behind it, right?... RIGHT?!4 -
"How would you reverse a string?"
One of the best Java interview questions I ever had! (no kidding)8 -
This jewel piece of code in Java:
if(String.valueOf(var1.toString( ) ).equalsIgnorecase(String.valueOf(var2.toString())){
//fuck something else here
}
String var1; //defined somewhere
String var2; //defined somewhere in the code
At this point I am not even mad 😂😂3 -
// Stupid JSON
// Tale of back-end ember api from hell
// Background: I'm an android dev attempting to integrate // with an emberjs / rails back-end
slack conversation:
me 3:51pm: @backend-dev: Is there something of in the documentation for the update call on model x? I formed the payload per the docs like so
{
"valueA": true,
"valueB": false
}
and the call returns success 200 but the data isn't being updated when fetching again.
----------------------------------------------------------------------------------------
backend-dev 4:00pm: the model doesn't look updated for the user are you sure you made the call?
----------------------------------------------------------------------------------------
me 4:01pm: Pretty sure here's my payload and a screen grab of the successful request in postman <screenshot attached>
----------------------------------------------------------------------------------------
backend-dev 4:05pm: well i just created a new user on the website and it worked perfectly your code must be wrong
----------------------------------------------------------------------------------------
me 4:07pm: i can test some more to see if i get any different responses
----------------------------------------------------------------------------------------
backend-dev 4:15pm: ahhhhhh... I think it's expecting the string "true", not true
----------------------------------------------------------------------------------------
me 4:16: but the fetch call returns the json value as a boolean true/false
----------------------------------------------------------------------------------------
backend-dev 4:18pm: thats a feature, the flexible type system allows us to handle all sorts of data transformations. android must be limited and wonky.
----------------------------------------------------------------------------------------
me 4:19pm: java is a statically typed language....
// crickets for ten minutes
me 4:30pm: i'll just write a transform on the model when i send an update call to perform toString() on the boolean values
----------------------------------------------------------------------------------------
backend-dev 4:35: great! told you it wasn't my documentation!
// face palm forever4 -
When I first began with Python I really missed the static typed checking from Java, I barely know anything about a returned object from a method and have to read the API extensively for every new library.
After a while I finally understand why Python is so powerful, the combination of dynamic typed language and rich default methods make the language unbeatable for your productivity.
While Java's Object only has toString(), hashCode(), equals() or clone(), Python's basic Class has every fucking method for every scenario I could ever image. No wonder that libraries like numpy or pandas work so well and fluidly.8 -
Null-propagation operator and null coalesce all in one line makes me tingly.
return registryKey.GetValue("foo")?.ToString()??"bar"; -
the irony appears to be that JavaScript is more consistent than rust
so let's say you want to create some enums to represent some potential values in a REST JSON payload
well you can implement Display trait but that won't determine the JSON output
you can make a as_str() method and that doesn't even make sense frankly, I guess it's not even a trait even though it's everywhere in the std library? (traits being rust's version of interfaces, so you'd think they should be consistent)
I have a halfway urge to say rust was a beloved language but then the foundations' drama made everyone escape the ship, leaving behind a mess
well evidently the answer is you use the stupid annotations:
enum Lang {
#[serde(rename = "en-US")]
EnUS,
}
well then this only works in serialization with serde. way to go.
how about if I have some JSON data that starts with numbers? I have an interval field in the REST that expects things like 1m, 15m denoting time scale
well no deal
because rust doesn't want enums starting with numbers
and here I thought rust was superior with its static typing. but I am having to rename things all the way down and nothing is consistent. this would be so trivial in JavaScript. and there's only one toString() method! and no interfaces people say you should use while nobody uses them!87 -
When the previous developer doesn't appear to know what casting is...
var foo = Convert.ToBoolean(objDictionary["someKey"].ToString());1 -
Just wasted two hours because C# float.parse only allows dots for decimal places and ignores commas..... But float.tostring uses a comma WTF.
I was writing an obj file exporting the vertices with tostring, then when loading the model would show up broken but in other 3d applications it worked.
Who did come up this bright idea ?2 -
!rant
If (LocalDateTime.now().toString(DateTimeFormatter.format(“yyyy-MM-dd”)).equals(“2017/10/17”)){
human.age++;
System.out.println(“Happy birthday old bastard!”);
}4 -
This will never clash:
static createGuid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + s4() + s4(); // Example => 'e014026082e6237b'
} -
(I'm not completely sure of what I'm saying here, so don't take this too seriously)
Settling on a language to write the api for ranterix is hard.
I'm finding a lot of things about elixir to be insanely good for a stable api.
But I'm having a lot of gripes with the most important elixir web framework, phoenix.
Take a look at this piece of code from the phoenix docs:
defmodule Hello.Repo.Migrations.CreateUsers do
use Ecto.Migration
def change do
create table(:users) do
add :name, :string
add :email, :string add :bio, :string
add :number_of_pets, :integer
timestamps()
end
end
end
Jesus christ, I hate this shit.
Wtf are create, add and timestamps. Add is somehow valid inside the create, how the fuck is that considered good code? What happens if you call timestamps twice? It's all obscure "trust me, it works" code.
It appears to be written by a child.
js may have a million problems. But one thing I like about CJS (require) or ESM (import) is that there's nothing unexplained. You know where the fuck most things come from.
You default export an eatShit() function on one file and import it from another, and what do you get?
The goddamn actual eatShit function.
require is a function the same way toString is a function and it returns whatever the fuck you had exported in the target file.
Meanwhile some dynamic langs are like "oh, I'll just export only some lang construct that i expect you to specify and put that shit in fucking global of the importing file".
Js is about the fucking freedom. It won't decide for you what things will files export, you can export whatever the fuck you want, strings, functions, classes, objects or even nothing at all, thanks to module.exports object or export statement.
And in js, you can spy on anything external, for example with (...args) => debugger; fnToSpyOn(...args)
You can spoof console.log this way to see what the fuck is calling it (note: monkey patching for debugging = GOOD, for actual programming = DOGSHIT)
To be fair though, that is possible because of being a dynamic lang and elixir is kind of a hybrid typed lang, fair enough.
But here's where i drop the shit.
Phoenix takes it one step further by following the braindead ruby style of code and pretty DSLs.
I fucking hate DSLs, I fucking hate abstraction addiction.
Get this, we're not writing fucking poetry here. We're writing programs for machines for them to execute.
Machines are not humans with emotions or creativity, nor feel.
We need some level of abstraction to save time understanding source code, sure.
But there has to be a balance. Languages can be ergonomic for humans, but they also need to be ergonomic for algorithms and machines.
Some of the people that write "beautiful" "zen" code are the folks that think that everyone who doesn't push the pretty code agenda is a code elitist that doesn't want "normal" people to get into programming.
Programming is hard, man, there's no fucking way around it.
Sometimes operating system or even hardware details bleed into code.
DSLs are one easy way to make code really really easy to understand, but also make it really fucking hard to debug or to lose "programming meaning".7 -
Sydochen has posted a rant where he is nt really sure why people hate Java, and I decided to publicly post my explanation of this phenomenon, please, from my point of view.
So there is this quite large domain, on which one or two academical studies are built, such as business informatics and applied system engineering which I find extremely interesting and fun, that is called, ironically, SAD. And then there are videos on youtube, by programmers who just can't settle the fuck down. Those videos I am talking about are rants about OOP in general, which, as we all know, is a huge part of studies in the aforementioned domain. What these people are even talking about?
Absolutely obvious, there is no sense in making a software in a linear pattern. Since Bikelsoft has conveniently patched consumers up with GUI based software, the core concept of which is EDP (event driven programming or alternatively, at least OS events queue-ing), the completely functional, linear approach in such environment does not make much sense in terms of the maintainability of the software. Uhm, raise your hand if you ever tried to linearly build a complex GUI system in a single function call on GTK, which does allow you to disregard any responsibility separation pattern of SAD, such as long loved MVC...
Additionally, OOP is mandatory in business because it does allow us to mount abstraction levels and encapsulate actual dataflow behind them, which, of course, lowers the costs of the development.
What happy programmers are talking about usually is the complexity of the task of doing the OOP right in the sense of an overflow of straight composition classes (that do nothing but forward data from lower to upper abstraction levels and vice versa) and the situation of responsibility chain break (this is when a class from lower level directly!! notifies a class of a higher level about something ignoring the fact that there is a chain of other classes between them). And that's it. These guys also do vouch for functional programming, and it's a completely different argument, and there is no reason not to do it in algorithmical, implementational part of the project, of course, but yeah...
So where does Java kick in you think?
Well, guess what language popularized programming in general and OOP in particular. Java is doing a lot of things in a modern way. Of course, if it's 1995 outside *lenny face*. Yeah, fuck AOT, fuck memory management responsibility, all to the maximum towards solving the real applicative tasks.
Have you ever tried to learn to apply Text Watchers in Android with Java? Then you know about inline overloading and inline abstract class implementation. This is not right. This reduces readability and reusability.
Have you ever used Volley on Android? Newbies to Android programming surely should have. Quite verbose boilerplate in google docs, huh?
Have you seen intents? The Android API is, little said, messy with all the support libs and Context class ancestors. Remember how many times the language has helped you to properly orient in all of this hierarchy, when overloading method declaration requires you to use 2 lines instead of 1. Too verbose, too hesitant, distracting - that's what the lang and the api is. Fucking toString() is hilarious. Reference comparison is unintuitive. Obviously poor practices are not banned. Ancient tools. Import hell. Slow evolution.
C# has ripped Java off like an utter cunt, yet it's a piece of cake to maintain a solid patternization and structure, and keep your code clean and readable. Yet, Cs6 already was okay featuring optionally nullable fields and safe optional dereferencing, while we get finally get lambda expressions in J8, in 20-fucking-14.
Java did good back then, but when we joke about dumb indian developers, they are coding it in Java. So yeah.
To sum up, it's easy to make code unreadable with Java, and Java is a tool with which developers usually disregard the patterns of SAD. -
I hate when I just want to reference a camelCase variable or fileName.class in my .docx Word documentation and it actually bothers to try to correct me. Word is an application made by coders, I don't see why it can't figure out that I'm not wrong when I type ".toString()"2
-
Dear fucking MicroSoft,
I really like the C# language, but the default System types have some little fucks up.
Like, if the DateTime.ToString() accepts "HH" to display hours with leading 0, WHY THE FUCK DOESN'T TimeSpan.ToString()?
Truly yours,
ZioCain6 -
i have experience in mobile dev for 3 years,today i got interview for coding test,it have 10 question,i cant answer question 1 so it stuck there until time out.the question is so fcking simple but because i more focus on framework and only have basic in kotlin/dart so i really like dumb people when interview,the 3 years experience is gone just like noting,even i forget toString use () ( so toString() ) because usually vscode give suggest the method
-
new DateTime().toString("yyyy");
//Output 2017
🎆🎆🎆🎆🎆🎆
Happy new year .
🎆🎆🎆🎆🎆🎆
Brought to you by JodaTime 😉 -
I wish I could be the man who creates strings with .toString() or even `${variable}` consistently. Alas, ""+fuckThisShit.
-
when the stack trace wasn't included in the error logging
fuck me, how the fuck am i supposed to know where the exception occurred
perhaps i've taken it all for granted thinking that the default toString implementation of an exception would've included that5 -
My journey along Java continues and so I have discovered something I didn't know before:
If a subclass tries to call a method on its parent which it has not overridden, then it will call the method as if you hadn't used the keyword 'super' (and I think it will try to find it in the classpath and SDK).
Example 1:
public class SuperParent {
public String test(){
return "SuperParent";
}
}
public class Parent extends SuperParent {
}
public class Child extends Parent {
public String testChild(){
return super.test(); // same effect as test();
}
}
public class TestInheritance {
public static void main(String[] args) {
System.out.println(new Child().test()); // returns "SuperParent"
}
}
Example 2: with getClass():
public class Parent {
@Override
public String toString(){
return super.getClass().getSimpleName();
}
}
public class Child extends Parent {
}
public class TestInheritance {
public static void main(String[] args) {
System.out.println(new Child()); // prints "Child"
}
}
This here is of course a special case: .getClass() will always return the class name of its caller, so naturally in this case it returns Child and not Parent.
You would expect it to return "Parent" since you use 'super' in the overridden toString() but it returns the Class name of the Child (then there's something in programming languages such lexical scope and execution scope, which I'm not sure if it applies here).
The solution for this example is of course .getSuperClass().
Inheritance isn't always straight-forward.
References:
https://stackoverflow.com/questions...
https://stackoverflow.com/questions...2 -
Gonna love ChatGPT from time to time.
Best version of this method I wrote by hand was 7 lines. Now it's 3.
And it's perfectly readable.
private static DateOnly ParseDateArgument(GraphQLValue? argumentValue, IResolveFieldContext context)
{
return argumentValue switch
{
GraphQLStringValue strVal when DateOnly.TryParse(strVal.Value.ToString(), out var date) => date,
GraphQLVariable varVal when DateOnly.TryParse(context.Variables?.ValueFor(varVal.Name.StringValue)?.ToString(), out var date) => date,
_ => default
};
}1 -
A usefull function, everyone should have near by. May requires some optimisations.
/// <summary>
/// DoEs tHiS To tHe pRoViDeD StRiNg. StArTs aLwAyS WiTh a cApItAl
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string DoThIsToThEtExT(string s)
{
var array = s.ToCharArray();
Parallel.For(0, s.Length, (index) =>
{
if (index % 2 == 0)
{
array[index] = array[index].ToString().ToUpper()[0];
}
else
{
array[index] = array[index].ToString().ToLower()[0];
}
});
return new string(array);
}3 -
Can someone please explain me why the fuck the following doesn't work in C#?
Dictionary<string,object> mex=Json.Deserialize(data.ToString())as Dictionary<string,object>;
if(mex.ContainsKey("sessionId") && mex["sessionId"].ToString()!=tkn.GetSessionID())
the previous condition is NEVER true, but the following:
Dictionary<string,object> mex=Json.Deserialize(data.ToString())as Dictionary<string,object>;
if(mex.ContainsKey("sessionId") && mex["sessionId"]!=tkn.GetSessionID())
will actually work as expected.
tkn.GetSessionID() returns a string, of course
and mex["sessionId"] is always an object that contains a string in form of a number, like 152, 552, 6246 and so on and no, it won't ever contain any blank or other character
Fuck this fucking shit from C#8