Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: December 21, 2024, 10:12 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bit flipping
#11
RE: Bit flipping
(April 23, 2016 at 11:55 pm)Tiberius Wrote: Honestly, it seems to me like she was just trying to be difficult. Like Cthulhu said, there's no point in optimizing that code. Using if statements are just as valid a way of writing it, and in fact might be the more preferable way of writing it since it's more obvious to people what the code does.

I agree. There's not a need to optimize the code to this degree. I think if you use extra ifs and else statements, you'll lose one or two points, get a 23-24/25. The only way to get a perfect score is to have it optimized.

I'm a perfectionist and it is 100% against my nature to leave a problem unsolved if I think I can get it. If I were strapped for time, I'd have left it as it was. My code worked just fine with that if-else included.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great

PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Reply
#12
RE: Bit flipping
My long response was eaten.

In short - if the goal is optimization, using simple operators compiles down to a single instruction for each operator where a standard library call requires relatively significantly more overhead.

In this sort of application where optimization isn't needed, writing for clarity is superior. When I encounter code that is needlessly clever I want to stab things.
Reply
#13
RE: Bit flipping
Gotcha.

I would never try and be this 'clever' in an actual program I was writing. I understand the need to simplify things in certain cases, but especially in a case like this where the stack is barely even being touched, it's really making things more complicated for the programmer as well as anyone maintaining the code.

In discrete structures, though, it is a major part of the curriculum to simplify decision trees and statements with equivalencies. In that regard, this exercise has its uses. Especially as the next classes are assembly language and advanced data structures, which I'm told will be full of shite like this.

I equate it to creating your own linked list instead of using STL. I will hopefully never ever have to create a linked list ever again by creating my own node class/pointers. It is useful, however, to know what the STL is doing when you make a dynamic list.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great

PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Reply
#14
RE: Bit flipping
Hey, hey, making your own LL is fun and educational...
Reply
#15
RE: Bit flipping
(April 24, 2016 at 3:04 am)pool the great Wrote: Hey, hey, making your own LL is fun and educational...

If you like reinventing the wheel and creating implementations that are very likely to be buggier than the existing ones.

As an academic exercise, sure. In the real world, no way.
Reply
#16
RE: Bit flipping
(April 23, 2016 at 11:40 pm)Tiberius Wrote: What was her reasoning for making the code so efficient? I mean, it's great to write efficient code, but that's usually something you do in advanced programming classes rather than a discrete math class.

Bloody Mathematicians always write the worst code. Literally. You try refactoring their code and it's all variable names with single letters that you can't search for to check whether there is a side effect. Or non descriptive short function names that give no clue as to what the function does. The mindset of a mathematician is that you automatically know everything about their code.

The lecturer should be sent on a software engineering course.
Reply
#17
RE: Bit flipping
(April 24, 2016 at 3:10 am)Cthulhu Dreaming Wrote:
(April 24, 2016 at 3:04 am)pool the great Wrote: Hey, hey, making your own LL is fun and educational...

If you like reinventing the wheel and creating implementations that are very likely to be buggier than the existing ones.

As an academic exercise, sure. In the real world, no way.

I agree, very bad idea in the real world. A great idea to flex those node muscles as an exercise though.

I'd like to take this opportunity to share that I figured out how to implement a LL in a program all by myself with no help. Big Grin
Reply
#18
RE: Bit flipping
My current job is to sort out the code at a famous biological institute. Apparently the funders insisted that their code be sorted out. The bio-informaticians sit there making digital faeces that is grossly inefficient and can't in any way be combined with any other code or changed in any way. I have to come along and spend months refactoring it before I can even make a simple change.

I had considered getting into biology myself but I realised that even if I went off and did a degree or MSc I'd still be sorting out crappy code from bio-informaticians that can't code because there is such a great need for it. And the need is only ever going to grow because they can write crappy code faster than anyone can refactor it.

So once again in my career I'm doing software engineering for other people with fulfilling scientific careers even though I don't get the chance to do any science myself. I actually find software engineering really boring and tedious. I'm thinking of leaving science all together.
Reply
#19
RE: Bit flipping
I've had to write code for real time control...and have seen similar code written by someone with far more experience than me.
I tell you, it's worth knowing how to save CPU cycles, memory, stack, etc...

The craziest thing I've seen is the equivalent of a function call as a pre-compiler define. As long as you keep variable names consistent...it works.
Reply
#20
RE: Bit flipping
Craziest thing I ever saw was for an astronomical observatory. It consisted of about 66 dishes, each one the size of a house and full of different units producing data such as wind speed, humidity etc They had to save all this data in case anything went wrong and they had to correct the measurements. And this produced an awful lot of data. Being on top of a plateau in Chile, most hard disks didn't work because of the low air pressure. But it was still more cost efficient to buy 10, throw away 9 and use the 1 that did work rather than buy a ruggedised hard disk.

All well and good.

Except they used a 19 digit number to record a Julian date. That is all the microseconds that had passed since 4713 BCE. Even unix time from 1970 was only 12 digits! And they had to throw away the data after 2 or 3 days at most because they couldn't store all that data. And to make it worse, none of the data changed. It was just endless rows of the same number repeated again. They did not come up with any encoding solution, they just tried to save the raw data. I came up with a method in less than an hour which would have reduced the amount of data to 10% of its size in the normal case, and in the worst case not reduced it at all.

But it was ignored because the decision to record a Julian date to 19 digits was too prevalent in the system apparently. Or because it was Germany and I'm a woman. Fuck 'em.
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
  Coin Flipping Poll Tiberius 15 5764 April 19, 2010 at 1:00 pm
Last Post: Violet



Users browsing this thread: 1 Guest(s)