Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

Sockser posted:

Hey thread, I got a lovely bachelor's in computer science and at work I develop internal tools where nobody else will ever look at my code until I leave the company so I never really get feedback other than "it does/n't work"

How do I learn to be a better programmer and avoid doing dumb poo poo that crops up in this thread?

What exactly do you do? Java? Ruby? MUMPS? Do you have other co-workers to do code reviews with even if they are on another team? I also suggest reading a few good books. The first book I read on software as a craft was The Pragmatic Programmer. It's fairly language agnostic (I think there's some C++) but it talks about writing good clean code. Some other books I've read and enjoyed are Code Complete and Head First Design Patterns. I'm also reading Art of Unit Testing and it's written for .NET developers I think there is enough wisdom that would apply to at least Java. Also, try to get involved with your local user groups.

EDIT: Added Art of Unit Testing

Adbot
ADBOT LOVES YOU

Harik
Sep 9, 2001

From the hard streets of Moscow
First dog to touch the stars


Plaster Town Cop

Suspicious Dish posted:

In the same vein, I've seen a bug that manifested with (a && b) * 100. Don't write clever code.

Let me guess - it was a single-boolean test with a macro like "IS_FOO * 100" and IS_FOO got redefined to a && b without parens, which left it as a && b * 100. Close?

SurgicalOntologist
Jun 17, 2004

PleasingFungus posted:

This is all really terrible code, though, and more languages should discourage you from writing it!

Most people don't expect bools to be multiplying anything, and it'll cause double-takes and misunderstandings of code.

As Suspicious Dish said, just use the ternary. Don't try to write 'clever code'.

Surely it's okay in some contexts? Is it really so bad to, e.g., take the mean of a list of bools in order to get a percentage?

\/ \/ \/ Thank you.

SurgicalOntologist fucked around with this message at 20:59 on Dec 17, 2013

seiken
Feb 7, 2005

hah ha ha
Multiplying by booleans is perfectly concise and natural, e.g. http://en.m.wikipedia.org/wiki/Kronecker_delta and if you think it's terrible code you need to get out

a lovely poster
Aug 5, 2011

by Pipski

Sockser posted:

How do I learn to be a better programmer and avoid doing dumb poo poo that crops up in this thread?

Do the dumb poo poo, have things break horifically, learn why it's dumb.

Reading this thread/books/Pollyanna's posting will only get you so far, there's no real trick to programming. Practice.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Sockser posted:

Hey thread, I got a lovely bachelor's in computer science and at work I develop internal tools where nobody else will ever look at my code until I leave the company so I never really get feedback other than "it does/n't work"

How do I learn to be a better programmer and avoid doing dumb poo poo that crops up in this thread?

Quit and find a better job.

Seriously.

If you're always the smartest person in the room and you're not Dennis Ritchie or something, or you're in an area where there's no one you can really collaborate with, and you don't feel that you can really push yourself to improve on a continuous basis without any sort of outside forces, then you should move somewhere where there are outside forces. You should always be wary about picking up bad habits from crappy developers who advocate using println instead of the debugger because "it's too hard", etc.

If, for whatever reason, you can't quit, you should do what others suggest and work on public projects, get involved in your programming community, have peers/mentors discuss what you do, etc.

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off

seiken posted:

Multiplying by booleans is perfectly concise and natural, e.g. http://en.m.wikipedia.org/wiki/Kronecker_delta and if you think it's terrible code you need to get out

See, this kind of poo poo is why mathematicians write the worst code.



From work, found this piece of brilliant code yesterday. Before you read the below, think: how, using Python's tempfile library, would you create a temporary file to upload to Amazon S3?

Would you perhaps write this?

Python code:
    with tempfile.NamedTemporaryFile() as tf:
        tf.write(data)
        makeS3Client().put(tf.name, output_filename)
...

Nah, too simple. This is what I found:

Python code:
        #Get the name for a temp file to use
        tmp = tempfile.NamedTemporaryFile()
        tmpName = tmp.name
        tmp.close()

... #generate data

        f = open(tmpName, 'w')
        f.write(data)
        f.close()

        #Copy the file to S3
        s3_client.put(tmpName, outputS3File)

        #Delete the temp file
        os.unlink(tmpName)
The guy who wrote this is more of a Java guy than a Python guy. I wonder, does it show?

Hughlander
May 11, 2005

Suspicious Dish posted:

It's quite rare that you ever see zero voltage across a wire, even if it's treated as a logical zero. Real-world physics is dope, yo.

So you are saying that bools should coerce to floats and we have functions that compare them with an epsilon like nearlyTrue and nearlyFalse?

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
I've found being too comfortable is a good way to get extremely complacent. It's only when you're exposed to new things or have to adhere to a new standard that you can grow.

I had no loving clue how OOP and classes and dependency injection could help you out in a complex or big project until I got on a big, complex project. I didn't have a clue why you'd want layers of classes passing poo poo around, or why you'd want to inject one into the other. IoC was also a loving mystery.

Now I wonder why the hell you wouldn't do it for anything in production or for testing, since there's free poo poo you can download that does a lot of it for you. I think the problems are lack of education on the subject as much as the names not being very descriptive.

Opinion Haver
Apr 9, 2007

seiken posted:

Multiplying by booleans is perfectly concise and natural, e.g. http://en.m.wikipedia.org/wiki/Kronecker_delta and if you think it's terrible code you need to get out

But you don't write (i = j) * 2, you write \delta_{ij} * 2. The analogy would be if you wrote boolToInt(i == j) * 2, which isn't unreasonable.

Also don't take style advice from math unless you use single letter variable names and have a roughly 4:1 comment:LOC ratio.

JawnV6
Jul 4, 2004

So hot ...

Hughlander posted:

So you are saying that bools should coerce to floats and we have functions that compare them with an epsilon like nearlyTrue and nearlyFalse?

It's a trick question since you're likely to only get 10bit ADC across 5V so anything under 5mV wouldn't even show up on that.

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off

Hughlander posted:

So you are saying that bools should coerce to floats and we have functions that compare them with an epsilon like nearlyTrue and nearlyFalse?

Or, alternately, he might be saying that there isn't any real 'fundamental connection' between 1/0 and true/false, even in the context of EE.

Your way is funnier, though.

Sockser
Jun 28, 2007
Probation
Can't post for 3 hours!

gariig posted:

What exactly do you do? Java? Ruby? MUMPS? Do you have other co-workers to do code reviews with even if they are on another team? I also suggest reading a few good books. The first book I read on software as a craft was The Pragmatic Programmer. It's fairly language agnostic (I think there's some C++) but it talks about writing good clean code. Some other books I've read and enjoyed are Code Complete and Head First Design Patterns. I'm also reading Art of Unit Testing and it's written for .NET developers I think there is enough wisdom that would apply to at least Java. Also, try to get involved with your local user groups.

EDIT: Added Art of Unit Testing

Volmarias posted:

Quit and find a better job.

Seriously.

If you're always the smartest person in the room and you're not Dennis Ritchie or something, or you're in an area where there's no one you can really collaborate with, and you don't feel that you can really push yourself to improve on a continuous basis without any sort of outside forces, then you should move somewhere where there are outside forces. You should always be wary about picking up bad habits from crappy developers who advocate using println instead of the debugger because "it's too hard", etc.

If, for whatever reason, you can't quit, you should do what others suggest and work on public projects, get involved in your programming community, have peers/mentors discuss what you do, etc.

Because I develop internal tools, I get to write whatever the hell I want. A lot of what I do is C# simply because I inherited a lot of C# code. And I've worked to improve a lot of that, which recently went from scrapping one huge project (~45000 lines of code) and rewriting it (down to a nice, maintainable, ~1200 including unit tests) so it's not like I'm not actively engaging myself in writing good code or anything like that, I loving hate the majority of code that gets written here even in our release stuff (I'm one of maybe a dozen people in the company with a CS degree and not an engineering degree if that says anything)

I'm just looking for ways to expose myself to like, I dunno, higher concepts of CS and poo poo? Like that big discussion of strong vs weak typing that came up the last couple pages. My degree didn't cover that and I could almost guarantee I'd never come across that at work but I want to learn more about uh.... something?

I'm finding it hard to eloquently state what I mean here.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Work on other open source projects.

Tesseraction
Apr 5, 2009

Hughlander posted:

So you are saying that bools should coerce to floats and we have functions that compare them with an epsilon like nearlyTrue and nearlyFalse?

We're seeing the birth of the weak/dynamic truth concept that brings us closer to quantum computing.

Sockser posted:

Because I develop internal tools, I get to write whatever the hell I want.

Personally I write something and think "all right, it works, I'm brilliant!!" and then come back to it about two weeks of reading this thread later and go "holy poo poo, I'm awful!!" and refactor it until it fits what I've learned. Then I rinse and repeat until it stops happening.

Obviously I exclusively code in bash with occasional GNU coreutils usage.

Tesseraction fucked around with this message at 23:07 on Dec 17, 2013

Deus Rex
Mar 5, 2005

Zombywuf posted:

Any language where you can't do:
C++ code:
struct dicks {
  int farts;
};
struct butts {
  char *poop;
  dicks boner;
};
dicks a;
butts *b = (butts *)(&a);
has no claim to being weakly typed.

I'm not sure exactly who or what you're replying to, but this compiles just fine in C++ and as C (with appropriate typedefs added to the structs).

QuarkJets
Sep 8, 2008

PleasingFungus posted:

See, this kind of poo poo is why mathematicians write the worst code.

If knowing how to use a Kronecker delta means that you write the worst code then I guess all scientists and engineers write the worst code

(I'm not disagreeing)

Deus Rex posted:

I'm not sure exactly who or what you're replying to, but this compiles just fine in C++ and as C (with appropriate typedefs added to the structs).

He's replying to the weak vs strong typing discussion by providing a great example of weak typing and suggesting that any language that can't do the same is not weakly typed. He's not saying that it's bad code or that it won't compile

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
This is not a Coding Horror. I just want to put this out there for the people who care about women in tech.

Open Source Interns Outperform Industry Heavyweights In Linux Kernel Contributions

I've never been prouder of my coworkers in my life.

evensevenone
May 12, 2001
Glass is a solid.
Multiplying single booleans is a little weird, but say elementwise multiplication of an array of booleans by an array of something else doesn't seem that weird.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Surprised nobody posted this: http://www.secalert.net/2013/12/13/ebay-remote-code-execution/ and a followup: http://gynvael.coldwind.pl/n/ebay_rce_analysis_wrong_question_mark

Basically eBay uses eval(). (The guy seems to be wrong about how PHP strings work though, the real horror is eBay)

tef
May 30, 2004

-> some l-system crap ->

QuarkJets posted:

I think that having False and True be represented by integers has become so ingrained in so many languages

in different ways too

quote:

In VB 6, True has a numeric value of -1. False has a numeric value of 0.

The reason for this is because the Boolean data type is stored as a 16-bit signed integer. Therefore,
-1 evaluates to 16 1s in binary (11111111). False is 16 0s (00000000). This produces the relationship that has held throughout the evolution of BASIC: True = Not False.

Pseudo-God
Mar 13, 2006

I just love oranges!
So I finally found something worth posting:
code:
<div class="div">
Granted, it's no big deal, like some of the things I see here, but it was still pretty funny.

Jewel
May 2, 2009

tef posted:

in different ways too

:gonk: Oh no what have I done :gonk:

I like them being represented as integers but this...

Also how is "True = Not False" equivalent to "-1 = Not 0". 1 is "Not 0" in boolean logic in the most basic of circuitry and even if you went with their wacky logic wouldn't "-1 = Not 1". I have no idea to the reasoning behind that part (the reasoning between true being 11111111 and false being 00000000 is a whole 'nother set of garbage imo)

Edit: vvv I'm a moron :downs:

Jewel fucked around with this message at 11:28 on Dec 18, 2013

shrughes
Oct 11, 2008

(call/cc call/cc)
Um yeah, the fact that it's bitwise not is the reason.

qntm
Jun 17, 2009

Jewel posted:

I have no idea to the reasoning behind that part

http://en.wikipedia.org/wiki/Two%27s_complement

seiken
Feb 7, 2005

hah ha ha

Opinion Haver posted:

But you don't write (i = j) * 2, you write \delta_{ij} * 2. The analogy would be if you wrote boolToInt(i == j) * 2, which isn't unreasonable.

Also don't take style advice from math unless you use single letter variable names and have a roughly 4:1 comment:LOC ratio.

This kind of failure to be comfortable with the most basic rules of your language is why we end up with poo poo like if (bool_value == true) ....

Zombywuf
Mar 29, 2008

Ornedan posted:

I'm not sure that Haskell should be called weakly typed, though.

If the shoe fits :-)

QuarkJets posted:

He's replying to the weak vs strong typing discussion by providing a great example of weak typing and suggesting that any language that can't do the same is not weakly typed. He's not saying that it's bad code or that it won't compile

Yeah that.

shrughes
Oct 11, 2008

(call/cc call/cc)
Weak typed is just an ill-defined term. Maybe it means "has tons of idiotic implicit conversions". How many? Who knows.

Zombywuf
Mar 29, 2008

Sockser posted:

I'm just looking for ways to expose myself to like, I dunno, higher concepts of CS and poo poo? Like that big discussion of strong vs weak typing that came up the last couple pages. My degree didn't cover that and I could almost guarantee I'd never come across that at work but I want to learn more about uh.... something?

The joke is that strong typing and weak typing are not well defined terms. Everyone has their own idea of what they mean, so don't feel bad if you don't get it; just make up your own definitions and play along.

Otherwise, just read stuff. Sadly it's hard to find places on the Internet where people discuss programming in any kind of depth any more, caring about programming has become incredibly passe. This thread is actually one of the more knowledgeable parts of the web.

Amarkov
Jun 21, 2010

Zombywuf posted:

The joke is that strong typing and weak typing are not well defined terms. Everyone has their own idea of what they mean, so don't feel bad if you don't get it; just make up your own definitions and play along.

Otherwise, just read stuff. Sadly it's hard to find places on the Internet where people discuss programming in any kind of depth any more, caring about programming has become incredibly passe. This thread is actually one of the more knowledgeable parts of the web.

Just get a job on the C# or Java language development teams, and you can spend all of your time discussing this and other exciting issues!

may or may not be accurate

ninjeff
Jan 19, 2004

tef posted:

in different ways too
A weird result of this in VB, even today:
Visual Basic .NET code:
Imports System

Module Program
    Sub Main()
        Console.WriteLine(CInt(True))
        Console.WriteLine(Convert.ToInt32(True))
    End Sub
End Module
code:
-1
1

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
The "0 false, -1 true" convention has been used by Forth for a very long time. Words which consume a boolean value typically accept 0 as false and anything nonzero as true, while operators such as < produce 0/-1 "flags". Part of the justification for the feature is that by doing bitwise operations on flags you can remove some branches, as in the following idiom:

code:
( n a b -- n' )  < if 45 + then
( n a b -- n' )  < 45 and +
If you're unfamiliar with the idiom, of course, this is cryptic and overly clever. What is a good idea in a low-level systems programming language is not necessarily a good idea in your Excel macros.

a lovely poster
Aug 5, 2011

by Pipski
There's pretty much nothing worse than maintaining a codebase where someone decided to play code golf the entire time they were working on it. That's all I see when I look at those sorts of statements.

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.

ninjeff posted:

A weird result of this in VB, even today:
Visual Basic .NET code:
Imports System

Module Program
    Sub Main()
        Console.WriteLine(CInt(True))
        Console.WriteLine(Convert.ToInt32(True))
    End Sub
End Module
code:
-1
1
Don't worry they got a solution for that: http://msdn.microsoft.com/en-us/library/aa432714(office.12).aspx

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

shrughes posted:

Weak typed is just an ill-defined term. Maybe it means "has tons of idiotic implicit conversions". How many? Who knows.

Perhaps it's because English is weak-typed.

Sockser
Jun 28, 2007
Probation
Can't post for 3 hours!

Amarkov posted:

Just get a job on the C# or Java language development teams, and you can spend all of your time discussing this and other exciting issues!

may or may not be accurate

My fourth stint as a co-op at my current employer was as a developer intern, and our weekly meetings usually consisted of such, and I just kinda sat there with no idea what was going on.

And now I sit next to those same dudes and hear it every day and have no idea what the gently caress they're ever talking about.

Zombywuf
Mar 29, 2008

Sockser posted:

And now I sit next to those same dudes and hear it every day and have no idea what the gently caress they're ever talking about.

Your mistake may be assuming that they do :v:

tbh though, a dev meeting is almost certainly tied entirely to the codebase people are working on - the only way to understand the conversations would be to dive into the codebase and ask questions.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
I found an use for everybody's favorite Unicode character

Objective-C code:
    // Wiggle the selection point a little so that the whole text is displayed. There doesn't seem to be a better way
    if (messageTextHeightChanged && self.messageText.hasText) {
        NSRange messageTextSelection = self.messageText.selectedRange;
        self.messageText.selectedRange = NSMakeRange(messageTextSelection.location + messageTextSelection.length, 0);
        [self.messageText insertText:@"\U0001F4A9"];
        [self.messageText deleteBackward];
        self.messageText.selectedRange = messageTextSelection;
    }
The horror is UIKit

E:

Suspicious Dish posted:

In the same vein, I've seen a bug that manifested with (a && b) * 100. Don't write clever code.

!!(a && b) * 100 :catdrugs:

E2:

shrughes posted:

Um yeah, the fact that it's bitwise not is the reason.

In fact all operators in (Visual)Basic were bitwise. This is why And/Or don't short-circuit, hence the new logical operators AndAlso/OrElse introduced in VisualBasic.NET

hackbunny fucked around with this message at 20:24 on Dec 18, 2013

Scaevolus
Apr 16, 2007

People get all emotional when you start calling their language "weak", and smug when their language is "dynamic".

Adbot
ADBOT LOVES YOU

Steve French
Sep 8, 2003

Hughlander posted:

So you are saying that bools should coerce to floats and we have functions that compare them with an epsilon like nearlyTrue and nearlyFalse?

https://www.youtube.com/watch?v=yzitqjUI6ok

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply