[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Blame
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 69
Thread images: 7
File: someTIme.png (6 KB, 278x199) Image search: [Google]
someTIme.png
6 KB, 278x199
What is wrong with this code?

Also post some funny/WTF moments you have found in someone's code during code-review/blame etc.
>>
Nothing wrong
>>
>>51821712
Depends, seems like a safe way to make sure that you always have a value for SomeTime. Why not set the value inside of the constructor instead of checking the value of the variable every time you want to access it? Probably makes close to zero difference in performance though.
>>
>>51821940
This is the exact opposite of checking if you have a value for SomeTime. Keep thinking ;)

Hint: C#.net
>>
wasnt datetime a struct?
but that's just trivia only for folks who know c#...
>>
File: 1436683293364.jpg (18 KB, 400x300) Image search: [Google]
1436683293364.jpg
18 KB, 400x300
>>51821987
I don't c# but why is there a class to access a variable outside of the class? Shit seems tarded. Why not make it a function or put someTime inside of the SomeTime class?
>>
File: Spread_2_1000.png (640 KB, 1000x806) Image search: [Google]
Spread_2_1000.png
640 KB, 1000x806
>>51821712
Blame thread?
>>
>>51821712
DateTime (struct), null?

You funny OP, more like default(DateTime)

Also, its set first time its ever accessed, which may be 100 days ahead of program start, why you would want that

return someTime == default(DateTime) ? (someTime = DateTime.Now) : someTime;
>>
>>51822094
Good! I like you!

Finally not some CS101 braggin about execution speed of code with variable assignment in/outside of constructors :D
>>
>>51821712
Are you even allowed to override DateTime like this?
>>
File: ienumerableEnumerating.png (10 KB, 519x206) Image search: [Google]
ienumerableEnumerating.png
10 KB, 519x206
Ok, some more C# trauma.
>>
>>51822022
Spot the retarded new CS student
>>
>>51822094
I'm not C#, but does the compiler not notice you're trying to compare null with a struct and bitch about it?

"This doesn't work. What's wrong?" problems are always easier when you have error messages telling you how it's wrong. It at least gives a starting point to find the mistake. Though working in support you get used to people who don't know how to read error messages. "My computer stopped working, says something about a keyboard error. What's wrong?" Idunno, maybe the fucking keyboard!
>>
>>51822390

I think you can have nullable structs with the ? keyword
>>
>>51822390
CA 'should' show you, that you are doing some stupid things. But in some environments (quickly developing young companies) they don't treat CA warnings as errors.

More often you get there and there are already 10k CA warnings and nobody notices such fuckups as the one above.

Harsh reality of corporate "can you get this done today customer is annoyed already" world ;)
>>
>>51822421
Yes, but you need to tread lightly with ? symbol :)

Also it can be a pain in the neck for large software architecture, they tend to spread like AIDS with rookies on board.
>>
>>51822159
Since when is usage of a class an override?
Just storing that time of the world

>>51822152
Due I dont really see why one would assing a one time value of DateTime to a class at ctor. Not really necessary to know when the class was created except for TCP sessions and users.

And about optimization, does not really get faster than that, so i look beyond that

>>51822360
if(someCollection.Count() == 0) return

Is unnecessary because Where goes via this code anyways, double the wasted check if Count > 0

Would code
foreach(var current in ShitLoadOfObjects().Where(x => x.id == myObjId))
{
// to serious bussiness
}


>>51822390
The compiler will indeed give an error about it, sure have met that one way to often
>>
>>51822421
DateTime?
- Equals
System.Nullable<DateTime>

So yes.
>>
>>51821712
>camel case
dropped

thats just like coding in comic sans
>>
>>51821712
it should be
get
{
return someTime ?? ( someTime = DateTime.Now );
}
>>
>>51822493
What's wrong with it? For that matter, what's wrong with coding in comic sans?
>>
>>51822546
He should ask his next employer during interview about coding in camelCase etc.

And he will answer that they are maintaining some modules which are 20+ years old in C++ so whey rolled out hungarian notation to C# as well so older developers can read it easily, because that is what they are used to :D

That would be a bummer.
>>
>>51822493
Whats so bad about it?
>>
>>51822534
No! >>51822094
>>
>>51822534
Error:

Operator '??' cannot be applied to operands of type 'System.DateTime' and 'System.DateTime'

Expansion is "== null"

;^)
>>
(define some-time (current-time))


Damn, that was hard.
>>
>>51822612
Remove the reference to the system namespace and use an alternative DateTime that's a class not a struct.
>>
>>51822656
>Removing System from project, just so ?? can be used

Oh boy dis gon be gud!
>>
File: confused black guy ¿¿¿.png (291 KB, 600x512) Image search: [Google]
confused black guy ¿¿¿.png
291 KB, 600x512
>>51821712
>write a form with validation in javascript
>checkboxes aren't validating correctly
>insert an alert box somewhere to check to see if the variable is being assigned the correct value or any value at all
>it is
>wtf
>remove alert box
>refresh page
>it works now
>>
File: 2353254123.jpg (25 KB, 300x301) Image search: [Google]
2353254123.jpg
25 KB, 300x301
>>51821712
Get and or enable fxcop/stylecop/resharper.
>>
>>51822836
I have R# at work, no worries ;)
>>
>>51822656
Mike, we need to rebuild codebase.
This damn DateTime cannot be null and I want it to.... no not with ? at the end, true pure nulls please. Can you refactor the thing by Tuesday? :D

>>51822656
haha exactly
>>
do {
// some code
} while(false)


Turns out he did this so he could use break instead of goto with a label at the end.
>>
>>51822763
Reminds me of a message box on AT&T's (!!) website.
"please remove white spaces before and after email address"

Heyy! I can write a cool function for that, hire me plase :)
>>
>>51822883
LOL :D Good one.
>>
>>51822883
That's pretty common in C macros to have a body of code that can be terminated with a semicolon.
>>
>>51823143
I'm not a C guy so I am asking:

Couldn't you write separate function, so it would just exit (return;) if there is nothing to do instead of breaking?

And call it directly in the function above?
That would clean up some indentations imo, unless I don't understand the concept.

Thx for answer in advance.
>>
>>51823295
Sure. But sometimes you don't want to split things up that much.

Writing readable code is difficult.
>>
>>51822152
>Finally not some CS101 braggin about execution speed of code with variable assignment in/outside of constructors :D
No reputable universities actually teach C#. Have fun in Community College
>>
>>51823353
Now while smoking I was thinking (:D) ... writing separate functions in c/c++ can introduce more argument passing mumbo-jumbo and whole pointer-jitsu *& problem, and probably generate a bug if someone is sloppy, true dat?
High risk?
>>
>>51822883
That's not that uncommon desu, it's used to avoid using goto
>>
>>51823454
Are you retarded, in high school, or both?
>>
>>51823532
Both
>>
>>51823454
Splitting something off into a use-once function may make the code more readable and it may make it less readable. (More readable code means less bugs.) It depends on the case really.

>>51823532
Why are you being an ass?
>>
>>51823578
>Now while smoking I was thinking
>:D
>mumbo-jumbo and whole pointer-jitsu
>true dat?
I wonder why
>>
>>51823454
>probably generate a bug if someone is sloppy, true dat?
Yes, it's a big reason why incompetent programmers stay away from CS and stick to safer OOP languages. The trade-off is C is extremely fast compared to these languages and easier to optimize.
But than again for most programs speed and optimization aren't really a problem. There are however places that need it, such as Operating Systems and graphics library and the like
>>
>>51823709
>CS
meant C
>>
>>51823431
Nowhere C# is mentioned, I'm just bragging about some irrelevant shit just to say something.

Btw. I had 100% Java at the uni. I like java and linux but employer after uni said C# so now I do C#. Sometimes if you want to earn some cash you cannot work in the field you like the most, not always pleasant but that's what it is.
>>
>>51822152
I would imagine == has been overloaded to perform default(), there's plenty overloads by default so it wouldnt be shocking
>>
>>51823666
This serious face will not work for very long. Your parents may think you are the hacker who saved christmas eve by resetting that router last year but if you can't have a little laugh and immediately start calling people names you will have a very sad experience in the future. And sometimes attitude > skills so chillax man :)

Nice trips btw :D
>>
>>51823830
>hacker
Why would I want to be that?
I'm mathematician getting a degree in pure mathematics, senpai.
>>
>>51823771
True.

Or you could move somewhere to land a join you enjoy rather than just taking what's lying around in your current location after school.
>>
>>51823771
>I had 100% Java at the uni
That sounds awful. My Uni taught a mix of C++, C, Java, Assembly, Bash, Python etc...
Was there really no Systems Programming or Computer architecture class requirement at yours?
>>
>>51822612
>using the smiley with a carat nose
>>
>>51823948
>>51823771
> I had 100% Java at the uni
> uni
>>
>be in high school
>programming class
>get tasked to write alarm clock for a microcontroller with display
>no problem
>classmate calls me over and asks why his code doesn't work
>sigh, go and check what he wrote
printf("120");
printf("119");
printf("118");
...

>200 lines
>"Dude what. Use loops."
>"That's too difficult, Anon"
>teacher comes over
>his fucking face when seeing his code
>>
>>51824000
wow...that's amazing
>>
>>51823709
Yeah, regarding speed of execution vs speed of development tradeoff: i.e. in our codebase there is a massive amount of C/C++ but we always use them for very small / specialized performance critical modules.

Then c wizards usually wrap them up in into C# (PInvoke etc.) classes so we can focus on general architecture of the software, assume the libraries work, and release the software within this century.

>>51823907
You must be fun at parties

>>51823945
It's different when you are married, have a house, family and all you must do to get decent salary is just to walk and extra mile and learn some other technology.But yeah, choices choices.


>>51823993
It must be hard not to be able to be a part of discussion when you really want to huh? :)

>>51823948
Gee! And you must remember every single thing! ;)
There were some modules about c++/c and unix programming, but I did not choose to continue them afterwards, focused on Java.
>>
>>51824000
Oh god. Poor thing.
>>
>>51824000
I wonder if he at least copy and pasted every line or if he typed it all from scratch...
>>
File: 1447632994347.jpg (161 KB, 1462x1462) Image search: [Google]
1447632994347.jpg
161 KB, 1462x1462
>>51824000
Holy kek
>>
>>51824116
reminds me of another one from the same class
>look over to what the guy next to me is doing
>he copypasted like 50 instances of code
>wat. Well not my problem.
>later look again
>he's correcting every single line that he copypasted
>Say "Here, let me show you something, it's faster that way"
>I Ctrl+F and go to the replace tab
>make it replace all instances of code with the corrected one
>He looks at me amazed and says "Dude, you're a fucking freak"
>mfw
>>
>>51824165
I don't...previous generations at least had an excuse. Everyone that's a teenager today has been using computers literally their entire lives.
>>
>>51824072
>Gee! And you must remember every single thing!
Well of course not, but They definitely helped me understand the differences between programming languages and helped me become a better programmer through diversity and learning the flaws and uses of multiple languages. A programmer knowing only one programming language is akin to a musician learning only knowing one instrument, sure they might be really good, but a master knows multiple instruments and is able to bring their experiences from each of them together.
Of course that doesn't matter if you're contempt on being a one trick pony, but there will be consequences eventually.
>>
>>51824197
I think I was also the only one that indented his code, and the only one that knew used Var++ to increase a variable by 1.
The average age of the students was 18 and the entire class was about 'mechatronics and automatisation technology', so those people should not only be teenagers but at least show some interest in technology.
>>
>>51824212
g would be appalled at how the real world works. there's people out there making huge bux for being experts on mainframes just because it's cheaper for the bosses to pay them than to pay to upgrade
>>
>>51824276
I think most of /g/ already knows that desu
>>
>>51823804
public static bool operator ==(DateTime other)

date.operator==(null), must still pass the null to DateTime argument conversion, still error
>>
>>51823982
>Not using carat noce, you racist against snowmen now eh?
Thread replies: 69
Thread images: 7

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.