• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:47
CEST 18:47
KST 01:47
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro16 Preview Pt1: Fresh Flow6[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy21ByuL: The Forgotten Master of ZvT30
Community News
MaNa leaves Team Liquid15$5,000 WardiTV TLMC tournament - Presented by Monster Energy5GSL CK: More events planned pending crowdfunding7Weekly Cups (May 30-Apr 5): herO, Clem, SHIN win0[BSL22] RO32 Group Stage5
StarCraft 2
General
MaNa leaves Team Liquid Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Team Liquid Map Contest #22 - Presented by Monster Energy Quebec Clan still alive ? BGE Stara Zagora 2026 cancelled
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament $5,000 WardiTV TLMC tournament - Presented by Monster Energy RSL Revival: Season 5 - Qualifiers and Main Event GSL CK: More events planned pending crowdfunding Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 521 Memorable Boss The PondCast: SC2 News & Results Mutation # 520 Moving Fees Mutation # 519 Inner Power
Brood War
General
[ASL21] Ro16 Preview Pt1: Fresh Flow Leta's ASL Ro24 Review The Korean Terminology Thread ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL21] Ro16 Group A Escore Tournament StarCraft Season 2 [Megathread] Daily Proleagues [ASL21] Ro24 Group F
Strategy
Any training maps people recommend? Fighting Spirit mining rates Muta micro map competition What's the deal with APM & what's its true value
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Battle Aces/David Kim RTS Megathread General RTS Discussion Thread Starcraft Tabletop Miniature Game
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Canadian Politics Mega-thread European Politico-economics QA Mega-thread The China Politics Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
lurker extra damage testi…
StaticNine
How Streamers Inspire Gamers…
TrAiDoS
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2403 users

The Big Programming Thread - Page 375

Forum Index > General Forum
Post a Reply
Prev 1 373 374 375 376 377 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Zild.
Profile Joined June 2011
France10 Posts
October 18 2013 17:50 GMT
#7481
On October 19 2013 02:21 HumpingHydra wrote:
Is there anyone in this thread who has dealt specifically with python having come from a background of zero programming whatsoever? How long will it take? If I plan to get some sort of coop job within the realm of bioinformatics, is there a chance I can learn a significant amount of python before applying for jobs in the fall and ultimately into summer? Any advice would be nice. Thanks guys.


Well I will try to cover everything you want to know.
First of all python is a really good choice as a first language to learn, because it relies on higher level mecanisms compared to C for example, which means that you are quite close to the human language, opposed to binary (assembly).

A lot of new programmers are taught programming using Python, you could actually try out the courses from Berkeley at
http://inst.eecs.berkeley.edu/~cs61a/su12/ that cover a lot of Python and data structures.
Practice is the key word and the time required depends on your work, I guess that if you do this on your spare time you could actually understand the basics quite quickly.

I have no experience in bioinformatics so I can't tell the level of programming required but from what I have seen it is not trivial, but don't be afraid to apply and see what is expected of you.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2013-10-18 18:17:41
October 18 2013 18:17 GMT
#7482
Programming for sciences such as biology or physics is a different animal from computer science or software engineering or programming as a profession.

Usually you are writing programs to perform some mathematical calculations that you have designed on paper but are difficult to do by hand as it needs to be applied to thousands of lines in a matrix. In that sense, getting to the level of familiarity using Python required to do such calculations shouldn't take too much effort. If it does take longer than a few afternoons, then you may want to find a mentor to help get you get back on track.

The hardest part is just the first step. Once you can read some parts of the code, and look up what you don't know, then it's downhill from there. Think of it as another language to describe mathematics in.
Any sufficiently advanced technology is indistinguishable from magic
Abominous
Profile Joined March 2013
Croatia1625 Posts
October 18 2013 18:19 GMT
#7483
On October 19 2013 02:50 Zild. wrote:
Show nested quote +
On October 19 2013 02:21 HumpingHydra wrote:
Is there anyone in this thread who has dealt specifically with python having come from a background of zero programming whatsoever? How long will it take? If I plan to get some sort of coop job within the realm of bioinformatics, is there a chance I can learn a significant amount of python before applying for jobs in the fall and ultimately into summer? Any advice would be nice. Thanks guys.


Well I will try to cover everything you want to know.
First of all python is a really good choice as a first language to learn, because it relies on higher level mecanisms compared to C for example, which means that you are quite close to the human language, opposed to binary (assembly).

A lot of new programmers are taught programming using Python, you could actually try out the courses from Berkeley at
http://inst.eecs.berkeley.edu/~cs61a/su12/ that cover a lot of Python and data structures.
Practice is the key word and the time required depends on your work, I guess that if you do this on your spare time you could actually understand the basics quite quickly.

I have no experience in bioinformatics so I can't tell the level of programming required but from what I have seen it is not trivial, but don't be afraid to apply and see what is expected of you.

I might as well help with some courses.

https://www.coursera.org/course/programming2

https://www.coursera.org/course/programming1

Check out some of the books with good reviews on Amazon, if you cover couple of courses and read the books you should be all set. Just remember something that all programmers are taught, you are never "through" with programming, it's not something you can absolutely know, each and every day will be a new experience (same goes for every scientific field just not on such a daily basis I would dare to say).

Bioinformatics is a fast growing field and I applaud your interest, wish you good luck!
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
October 18 2013 18:50 GMT
#7484
From what I know, programming for natural sciences usually is either fairly basic like the aforementioned "implement this calculation", or high performance software that is run on supercomputers. And if it's written in python, it sure isn't the latter.
If you have a good reason to disagree with the above, please tell me. Thank you.
Cyx.
Profile Joined November 2010
Canada806 Posts
October 18 2013 18:50 GMT
#7485
On October 19 2013 02:21 HumpingHydra wrote:
Hey guys. I am a third year student in university getting my degree in biochemistry. My coop supervisor told me that it would be worth my while to learn a bit of python in my spare time if I would like to get a job within the realm of bioinformatics, and that its not too difficult(I mentioned that I've never really done any programming). However due to the fact I have essentially never done any programming I am unsure if this is worth pursuing. Is there anyone in this thread who has dealt specifically with python having come from a background of zero programming whatsoever? How long will it take? If I plan to get some sort of coop job within the realm of bioinformatics, is there a chance I can learn a significant amount of python before applying for jobs in the fall and ultimately into summer? Any advice would be nice. Thanks guys.

I learned Python starting from zero when I was in high school, and I'm now teaching my girlfriend to program using the same... It's a great language to learn in, and there's even a great wikibook called the Non-Programmer's Tutorial for Python 3 that will get you up and running with everything you need to know to start using Python pretty extensively in a couple of weeks if you work at it. Yes there's a chance you can learn enough Python for the jobs you're applying for by next summer, even a chance you could learn enough to be impressive on resumes you send out over the next couple months. Python can be picked up pretty quickly, don't be scared of it!
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
October 18 2013 22:36 GMT
#7486
Are people really using Python over R or matlab for bioinformatics?

I know Python is more popular but I would have thought that the sheer advantages R has would have made it better.

I feel R handles math better without the need of a math library since R is a statistical language. A language built for the analysis of data whereas python is general purpose.
R handles updates much better and you don't have to worry about people sticking to 2.7 python instead of going to 3.x python.
R has more consistent syntax for print statements. It also has more consistent naming conventions. Eg. Tkinter vs tkiner in python 2->3.
R's environment is set up automatically. Everyone uses the RGui or command shell to run programs and it's easy to copy and paste. Python has several IDEs and the defaults like Idlex are unstable and don't copy and paste data from the clipboard into the shell very well. You're set up with R from the start.
R has a beautiful cran repository that stores and keeps data on every single package and their compatibility and has an easy to set up installer. With python you have no idea if your package is compatible with your other packages or your environment (god help you if you're using windows). There's so many dependencies and binary installers are often hard to find.

I would have thought there were more support and better documentation for statistical analysis in R than in python.

Have you done any research to determine if people in bioinformatics are looking for python instead of R?
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
NB
Profile Blog Joined February 2010
Netherlands12045 Posts
October 19 2013 00:35 GMT
#7487
Im not sure about bioinfo but im taking an AI(Machine Learning) class and the instructor recommend to use Octave instead of matlab. According to my roommate who took this class before, Octave is pretty much matlab but more... 'open'?
Im daed. Follow me @TL_NB
wherebugsgo
Profile Blog Joined February 2010
Japan10647 Posts
October 19 2013 06:55 GMT
#7488
On October 19 2013 07:36 obesechicken13 wrote:
Are people really using Python over R or matlab for bioinformatics?

I know Python is more popular but I would have thought that the sheer advantages R has would have made it better.

I feel R handles math better without the need of a math library since R is a statistical language. A language built for the analysis of data whereas python is general purpose.
R handles updates much better and you don't have to worry about people sticking to 2.7 python instead of going to 3.x python.
R has more consistent syntax for print statements. It also has more consistent naming conventions. Eg. Tkinter vs tkiner in python 2->3.
R's environment is set up automatically. Everyone uses the RGui or command shell to run programs and it's easy to copy and paste. Python has several IDEs and the defaults like Idlex are unstable and don't copy and paste data from the clipboard into the shell very well. You're set up with R from the start.
R has a beautiful cran repository that stores and keeps data on every single package and their compatibility and has an easy to set up installer. With python you have no idea if your package is compatible with your other packages or your environment (god help you if you're using windows). There's so many dependencies and binary installers are often hard to find.

I would have thought there were more support and better documentation for statistical analysis in R than in python.

Have you done any research to determine if people in bioinformatics are looking for python instead of R?


R is definitely used for sequencing and large data sets for the reasons you mentioned.

However, any time that heavy mathematics/statistics is not required Python is preferred because of its ease of use, support advantages, and popularity in general in comparison to R.

Scripting and basic things in Python are much easier, and afaik there are more libraries to work with. It's definitely slower, but when you don't need to do intensive math Python is probably a better choice. If you're doing genomic sequencing or other things that require the analysis of large data sets, then R would clearly be the better choice.

As a completely unrelated aside, I've had some job interviews lately and I must stress that anyone looking for any sort of software development or data analysis job should be well-versed in algorithms and data structures. An interesting question I got the other day was this:

You're given an array of numbers such that every element in the array is duplicated except for one. Provide an efficient algorithm to determine the singleton element.

I came up with a really shitty answer at first in about 30 seconds, and then I was encouraged to find a more efficient solution, which took me another 3-4 minutes. Pretty interesting problem.
Sub40APM
Profile Joined August 2010
6336 Posts
Last Edited: 2013-10-19 07:14:30
October 19 2013 07:07 GMT
#7489
On October 19 2013 15:55 wherebugsgo wrote:
Show nested quote +
On October 19 2013 07:36 obesechicken13 wrote:
Are people really using Python over R or matlab for bioinformatics?

I know Python is more popular but I would have thought that the sheer advantages R has would have made it better.

I feel R handles math better without the need of a math library since R is a statistical language. A language built for the analysis of data whereas python is general purpose.
R handles updates much better and you don't have to worry about people sticking to 2.7 python instead of going to 3.x python.
R has more consistent syntax for print statements. It also has more consistent naming conventions. Eg. Tkinter vs tkiner in python 2->3.
R's environment is set up automatically. Everyone uses the RGui or command shell to run programs and it's easy to copy and paste. Python has several IDEs and the defaults like Idlex are unstable and don't copy and paste data from the clipboard into the shell very well. You're set up with R from the start.
R has a beautiful cran repository that stores and keeps data on every single package and their compatibility and has an easy to set up installer. With python you have no idea if your package is compatible with your other packages or your environment (god help you if you're using windows). There's so many dependencies and binary installers are often hard to find.

I would have thought there were more support and better documentation for statistical analysis in R than in python.

Have you done any research to determine if people in bioinformatics are looking for python instead of R?


R is definitely used for sequencing and large data sets for the reasons you mentioned.

However, any time that heavy mathematics/statistics is not required Python is preferred because of its ease of use, support advantages, and popularity in general in comparison to R.

Scripting and basic things in Python are much easier, and afaik there are more libraries to work with. It's definitely slower, but when you don't need to do intensive math Python is probably a better choice. If you're doing genomic sequencing or other things that require the analysis of large data sets, then R would clearly be the better choice.

As a completely unrelated aside, I've had some job interviews lately and I must stress that anyone looking for any sort of software development or data analysis job should be well-versed in algorithms and data structures. An interesting question I got the other day was this:

You're given an array of numbers such that every element in the array is duplicated except for one. Provide an efficient algorithm to determine the singleton element.

I came up with a really shitty answer at first in about 30 seconds, and then I was encouraged to find a more efficient solution, which took me another 3-4 minutes. Pretty interesting problem.

If you are doing really large data sets you are not going to use just your harddrivel, you are going to want to use some kind of distributed system so the mathematical speed of R suddenly becomes not as advantageous and the scripting advantage of Python gets even more useful.

What was your answer?
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
October 19 2013 07:14 GMT
#7490
what are your opinions about working as an online freelancer vs working in a firm/office environment? (as a programmer).
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
October 19 2013 07:25 GMT
#7491
--- Nuked ---
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
October 19 2013 07:33 GMT
#7492
On October 19 2013 15:55 wherebugsgo wrote:
You're given an array of numbers such that every element in the array is duplicated except for one. Provide an efficient algorithm to determine the singleton element.

Is that the exact wording of the question? Does "duplicated" mean that the duplicate and the original are in unrelated slots of the array, or are they adjacent? Can there be multiple sets of duplicates of the same number, as in 2, 4, 6 of the number? What range are the numbers from?

Then there also is the question how one defines efficient. It's an inefficient use of programmer time if you don't just use some stupid algorithm that works and is easy to read and understand. Unless that piece of code is a performance bottleneck that needs to be faster. But I'm going to assume that low execution time is the goal here anyways.
If you have a good reason to disagree with the above, please tell me. Thank you.
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-10-19 07:35:39
October 19 2013 07:35 GMT
#7493
On October 19 2013 16:07 Sub40APM wrote:
Show nested quote +
On October 19 2013 15:55 wherebugsgo wrote:
On October 19 2013 07:36 obesechicken13 wrote:
Are people really using Python over R or matlab for bioinformatics?

I know Python is more popular but I would have thought that the sheer advantages R has would have made it better.

I feel R handles math better without the need of a math library since R is a statistical language. A language built for the analysis of data whereas python is general purpose.
R handles updates much better and you don't have to worry about people sticking to 2.7 python instead of going to 3.x python.
R has more consistent syntax for print statements. It also has more consistent naming conventions. Eg. Tkinter vs tkiner in python 2->3.
R's environment is set up automatically. Everyone uses the RGui or command shell to run programs and it's easy to copy and paste. Python has several IDEs and the defaults like Idlex are unstable and don't copy and paste data from the clipboard into the shell very well. You're set up with R from the start.
R has a beautiful cran repository that stores and keeps data on every single package and their compatibility and has an easy to set up installer. With python you have no idea if your package is compatible with your other packages or your environment (god help you if you're using windows). There's so many dependencies and binary installers are often hard to find.

I would have thought there were more support and better documentation for statistical analysis in R than in python.

Have you done any research to determine if people in bioinformatics are looking for python instead of R?

R is definitely used for sequencing and large data sets for the reasons you mentioned.

However, any time that heavy mathematics/statistics is not required Python is preferred because of its ease of use, support advantages, and popularity in general in comparison to R.

Scripting and basic things in Python are much easier, and afaik there are more libraries to work with. It's definitely slower, but when you don't need to do intensive math Python is probably a better choice. If you're doing genomic sequencing or other things that require the analysis of large data sets, then R would clearly be the better choice.

As a completely unrelated aside, I've had some job interviews lately and I must stress that anyone looking for any sort of software development or data analysis job should be well-versed in algorithms and data structures. An interesting question I got the other day was this:

You're given an array of numbers such that every element in the array is duplicated except for one. Provide an efficient algorithm to determine the singleton element.

I came up with a really shitty answer at first in about 30 seconds, and then I was encouraged to find a more efficient solution, which took me another 3-4 minutes. Pretty interesting problem.

If you are doing really large data sets you are not going to use just your harddrivel, you are going to want to use some kind of distributed system so the mathematical speed of R suddenly becomes not as advantageous and the scripting advantage of Python gets even more useful.

What was your answer?

What scripting advantage?
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
wherebugsgo
Profile Blog Joined February 2010
Japan10647 Posts
October 19 2013 11:07 GMT
#7494
On October 19 2013 16:33 spinesheath wrote:
Show nested quote +
On October 19 2013 15:55 wherebugsgo wrote:
You're given an array of numbers such that every element in the array is duplicated except for one. Provide an efficient algorithm to determine the singleton element.

Is that the exact wording of the question? Does "duplicated" mean that the duplicate and the original are in unrelated slots of the array, or are they adjacent? Can there be multiple sets of duplicates of the same number, as in 2, 4, 6 of the number? What range are the numbers from?

Then there also is the question how one defines efficient. It's an inefficient use of programmer time if you don't just use some stupid algorithm that works and is easy to read and understand. Unless that piece of code is a performance bottleneck that needs to be faster. But I'm going to assume that low execution time is the goal here anyways.


I paraphrased, but basically you can expect to encounter two of every element in the array except for one element. The array is unsorted and the duplicates can appear anywhere. There won't be multiple (read: more than 2) instances of the same number, though the answer would remain the same for even-number duplicates-i.e. you could have 4 of the same number and 2 of another and 6 of another and finding the singleton still works the same.

There is no specification on the range of the numbers, though you can assume that you won't need multiple data structures to represent a single number. i.e. if it makes it easier for you, assume they are 32 bit ints or whatever.

My first solution required O(nlogn) time, and O(1) space. I pretty quickly realized that the time complexity can be improved to O(n) time and there's a relatively simple way of doing that by adding a data structure that takes O(n) space, but the "brilliant" answer (as the interviewer described it-I'd call it elegant) requires no additional space and is also O(n) time.

+ Show Spoiler [my shitty answer] +
Sort the array, then step through the array until you find that two consecutive elements are not the same. Sorting takes O(nlogn) time and stepping through the array takes O(n) time; O(nlogn + n) is in O(nlogn).

You could use radix sort and get an O(n) sort, I suppose.


+ Show Spoiler [an approximately equally shitty answer] +
Instead of sorting the array, maintain a hash table and a second sum variable. Iterate through the array and for each integer, check if it's in the hash table. If it isn't, then add it to the sum, and store it. If it is, then subtract it from the sum. When we've gone through the entire array, the singleton is the only element we never subtracted, thus the sum variable is the singleton.

This works in O(n) time since hash accesses are O(1), and we need O(n) space for the hash table.


+ Show Spoiler [the model answer] +

Just iterate through the array and XOR everything together. A[0] XOR A[1] XOR .... XOR A[n]. The result of this computation is the singleton element.

This works since XOR is commutative and associative. a XOR a is just 0, and 0 XOR a is a. Since all of the elements are duplicated except one of them, all the duplicates will XOR out to 0 and then the singleton will be left at the end.

This holds true also for arrays in which you have even multiples of elements, not just duplicates, though it fails when there are odd multiples.


If you guys like this sort of stuff or need interview practice, here's a few more interesting problems I encountered at career fairs/interviews and company visit sessions:

1. This problem is similar to the one I posed before, but it has a pretty major twist.

The problem statement is to find the missing integer in the array with the following rules:

a. An array A contains every integer from 0 to N except for one of them.
b. The elements of the array A may appear in any order.
c. We can't actually access an entire element of the array all at once. In other words if you index the array you won't get back the whole element. + Show Spoiler +
in other words, normally if you access an array element at index i, you would call A[i] and you would be returned the element at the ith position in A. In this problem you can't do that.
Instead, what you can do is ask for the jth bit of the ith element of the array. In other words, I could ask for the 4th bit of the first element of A, and I would be returned the bit in the 4th position of the element ordinarily given by A[0].
d. The algorithm must return the missing integer by looking through at most O(N) bits.




2. Give an approach (or code) to writing an equivalent of the C function atoi. + Show Spoiler +
I've also been asked how to implement strlen
If you're not a C programmer, atoi is a function that converts an ASCII string to an integer. Describe the limitations or shortcomings of your approch (or code) in as much detail as you can.




3. Suppose we have a function that computes rand2() (i.e. a fair coin toss-it outputs 1 or 2 with equal probability). Design an algorithm that uses this function to simulate a fair die roll, i.e. a function that should output a random number from 1 to 6 with equal probability.

spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2013-10-19 11:57:55
October 19 2013 11:50 GMT
#7495
I wouldn't call that either brilliant or elegant. Sure, you should know what the operation does, but that doesn't mean you should ever use it unless you're forced to by run time or other constraints. That's the kind of look-I'm-so-clever code I tried to write years ago. Now when I realize I wrote something like that I just delete the whole thing and replace it with a piece of code that doesn't require any bitwise operations on values that aren't explicitly declared as bitflags.

And god knows what will happen when you one day decide that you want floats instead of ints and forget to change that code.

+ Show Spoiler +
Or am I the only one who finds that XOR barely ever is appropriate?
If you have a good reason to disagree with the above, please tell me. Thank you.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2013-10-19 12:18:02
October 19 2013 11:58 GMT
#7496
--- Nuked ---
gedatsu
Profile Joined December 2011
1286 Posts
October 19 2013 12:01 GMT
#7497
On October 19 2013 20:50 spinesheath wrote:
I wouldn't call that either brilliant or elegant. Sure, you should know what the operation does, but that doesn't mean you should ever use it unless you're forced to by run time or other constraints. That's the kind of look-I'm-so-clever code I tried to write years ago. Now when I realize I wrote something like that I just delete the whole thing and replace it with a piece of code that doesn't require any bitwise operations on values that aren't explicitly declared as bitflags.

And god knows what will happen when you one day decide that you want floats instead of ints and forget to change that code.

+ Show Spoiler +
Or am I the only one who finds that XOR barely ever is appropriate?

Why wouldn't it work on floats?
misirlou
Profile Joined June 2010
Portugal3292 Posts
October 19 2013 12:22 GMT
#7498
On October 19 2013 21:01 gedatsu wrote:
Show nested quote +
On October 19 2013 20:50 spinesheath wrote:
I wouldn't call that either brilliant or elegant. Sure, you should know what the operation does, but that doesn't mean you should ever use it unless you're forced to by run time or other constraints. That's the kind of look-I'm-so-clever code I tried to write years ago. Now when I realize I wrote something like that I just delete the whole thing and replace it with a piece of code that doesn't require any bitwise operations on values that aren't explicitly declared as bitflags.

And god knows what will happen when you one day decide that you want floats instead of ints and forget to change that code.

+ Show Spoiler +
Or am I the only one who finds that XOR barely ever is appropriate?

Why wouldn't it work on floats?


I think this precise example works (because youre checking for equalitys and floats are still equal if they have the same bits) but the general rule is that it's bad practice to use bit operations on numeric values. For example, if you want to divide an int by 2 or check if it's even and use bit shifting, it wont work if you change the int to float.
Abominous
Profile Joined March 2013
Croatia1625 Posts
October 19 2013 12:41 GMT
#7499
On October 19 2013 09:35 NB wrote:
Im not sure about bioinfo but im taking an AI(Machine Learning) class and the instructor recommend to use Octave instead of matlab. According to my roommate who took this class before, Octave is pretty much matlab but more... 'open'?

It's more or less the same but only Matlab has much more libraries, functions etcetera, but for your basic work (I take it by professor you mean dr. Ng from the course I recommended you? ) in the course Octave will suffice, since the license for using Matlab costs, A LOT!
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2013-10-19 14:59:54
October 19 2013 14:56 GMT
#7500
On October 19 2013 21:01 gedatsu wrote:
Show nested quote +
On October 19 2013 20:50 spinesheath wrote:
I wouldn't call that either brilliant or elegant. Sure, you should know what the operation does, but that doesn't mean you should ever use it unless you're forced to by run time or other constraints. That's the kind of look-I'm-so-clever code I tried to write years ago. Now when I realize I wrote something like that I just delete the whole thing and replace it with a piece of code that doesn't require any bitwise operations on values that aren't explicitly declared as bitflags.

And god knows what will happen when you one day decide that you want floats instead of ints and forget to change that code.

+ Show Spoiler +
Or am I the only one who finds that XOR barely ever is appropriate?

Why wouldn't it work on floats?

Well, if you try to consider this as a not completely made up problem, then the array would have to come from somewhere. Chances are, the numbers aren't created by exactly duplicating all but one value in another array. You're usually not guaranteed that the same float value always has the same bit signature. Am I even guaranteed that after I assign one float to another, bitwise equality for the two floats holds? I guess it's likely, and probably stated so in the language specifications, but with denormalization and such there might be alternative implementations.

Generally, I don't like making assumptions about an implementation even on basic data types like integers, and especially not floats, unless I have a good reason. I prefer to treat numbers as numbers where I have normal arithmetic operations like addition and multiplication. If I use an integer as a string of bitflags, then I prefer to use bitwise operations only and never treat it as a number.

Sure, in this special case the XOR is fine as it's just one simple line of code. But in reality things often get more complex and then I'd prefer not having to think about the details of XOR in special contexts.
If you have a good reason to disagree with the above, please tell me. Thank you.
Prev 1 373 374 375 376 377 1032 Next
Please log in or register to reply.
Live Events Refresh
Monday Night Weeklies
16:00
#47
RotterdaM671
IndyStarCraft 86
SteadfastSC72
BRAT_OK 69
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 671
Hui .289
mouzHeroMarine 280
TKL 187
ProTech147
IndyStarCraft 86
SteadfastSC 72
BRAT_OK 69
StarCraft: Brood War
Sea 6641
Calm 5349
Bisu 3565
Horang2 2406
Jaedong 1666
Mini 1130
Britney 840
EffOrt 740
BeSt 430
Larva 411
[ Show more ]
Stork 375
Soulkey 214
firebathero 211
ggaemo 174
actioN 156
Rush 150
Dewaltoss 131
Zeus 98
Hyun 76
Barracks 63
Mind 53
zelot 32
ToSsGirL 26
Rock 22
Movie 19
Terrorterran 18
GoRush 13
IntoTheRainbow 10
Sexy 10
Dota 2
qojqva2550
420jenkins267
BananaSlamJamma113
Counter-Strike
fl0m6133
pashabiceps1547
Other Games
Grubby1713
FrodaN1173
B2W.Neo958
hiko845
Beastyqt372
XBOCT329
ArmadaUGS182
KnowMe118
QueenE88
Sick59
Trikslyr39
Mew2King35
MindelVK0
Organizations
Counter-Strike
PGL201
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Shameless 56
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis1640
• Jankos1451
• TFBlade1110
Other Games
• Shiphtur163
Upcoming Events
OSC
7h 13m
Afreeca Starleague
17h 13m
Snow vs PianO
hero vs Rain
WardiTV Map Contest Tou…
17h 13m
GSL
19h 13m
PiGosaur Cup
1d 7h
CranKy Ducklings
1d 16h
Kung Fu Cup
1d 19h
Replay Cast
2 days
The PondCast
2 days
WardiTV Map Contest Tou…
2 days
[ Show More ]
Replay Cast
3 days
Escore
3 days
WardiTV Map Contest Tou…
3 days
Korean StarCraft League
4 days
CranKy Ducklings
4 days
WardiTV Map Contest Tou…
4 days
IPSL
4 days
WolFix vs nOmaD
dxtr13 vs Razz
BSL
5 days
Sparkling Tuna Cup
5 days
WardiTV Map Contest Tou…
5 days
Ladder Legends
5 days
BSL
6 days
IPSL
6 days
JDConan vs TBD
Aegong vs rasowy
Replay Cast
6 days
Replay Cast
6 days
Wardi Open
6 days
Afreeca Starleague
6 days
Bisu vs Ample
Jaedong vs Flash
Monday Night Weeklies
6 days
Liquipedia Results

Completed

Escore Tournament S2: W2
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
StarCraft2 Community Team League 2026 Spring
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W3
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
RSL Revival: Season 5
WardiTV TLMC #16
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.