- This topic has 43 replies, 19 voices, and was last updated 7 years ago by molgrips.
-
One for the programmers
-
growingladFree Member
I received an email about some courses on Python.
I probably won’t go as it’s in the UK, but the following question interested me.
They say that a basic knowledge of programming is required and if you understand the following question it’s a good test:a = b = c =’Arista’
Now I have zero programming experience (apart from a ZX81 about 35 years ago.
I had a quick look on tut internet, but couldn’t find anything useful, just interested in the answer.
My Luddite brain says that if you use a, or b, or c then it equals Arista??
Please humour me and tell me the answer.
rossburtonFree MemberYeah, that’s right. Not exactly a great test for “basic programming” as anyone who can remember their pre-GCSE maths would have encountered symbolic expressions like that.
growingladFree Memberwhhhhooooaooaoaoo…That’s the type of web site I believe is the work of the Devil. (But thanks for the response 🙂 )
I think I may have to pick up some of this er Python….I think I’m going to struggle to make retirement without knowing something.
CougarFull MemberIn (some) languages, “=” is assignment and our more traditional use of the equals sign, that of comparison, is “==”.
So,
a = b
would assign the value ofb
toa
, whereasa == b
would be part of a test to see whether they’re the same.(Back in your Sinclair BASIC days, the same symbol was used for both operations and its meaning was derived from context.)
TurnerGuyFree MemberYeah, that’s right. Not exactly a great test for “basic programming” as anyone who can remember their pre-GCSE maths would have encountered symbolic expressions like that.
apparently it is – a mathmatician type might look at that and declare that is rubbish and have a harder time becoming a decent programmer, whereas someone that is more likely to take to programming will accept it, thinking that a b and c are just labels to memory locations.
linguists are suppossed to make decent programmers as well.
jaymoidFull MemberYeah I’m a java dev and that wouldn’t fly in Java land (as it stands, you’d need to declare all variables first and then it works)… the best way to learn to program is to give it a go, your example was very quick to have a go and see what happened. You just need to get set up and you’re away! Python is quick and easy as it has a REPL (Read–eval–print loop) shell to try out code easily.
[bash]$ python
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.>>> a = b = c = ‘Arista’
>>> a
‘Arista’
>>> b
‘Arista’
>>> c
‘Arista’molgripsFree MemberYeah I think how that would work would depend on the language. But a more important thing to teach is why never to write stuff like that!
apparently it is – a mathmatician type might look at that and declare that is rubbish and have a harder time becoming a decent programmer, whereas someone that is more likely to take to programming will accept it, thinking that a b and c are just labels to memory locations.
That’s nonsense, tbh. None of the concepts are difficult, someone bright enough to be good at maths is easily capable of understanding the difference between = in maths and = in languages. That kind of language detail is really easy and not what makes good programmers.
There are plenty of people who know how to operate the language just fine but can’t write clear code. To be good, you need to be able to deconstruct problems and model them in a way that is going to be clear, modifiable and extendable. And you need to understand businesses and hence people too. There are many programmers who will spend ages crafting something clever pants when it’s not what’s actually needed or what’s best.
*rant over*
CougarFull MemberBut a more important thing to teach is why never to write stuff like that!
Hm, that’s a good point, it does feel a bit like someone’s put it just to try to be clever. As a “challenge” it smacks a bit of the sort of thing you get on Facebook with Lolcat text suggesting only 2% of people will get this right, like and share if you get it!
aracerFree MemberThose irritating users who think they know better what’s needed or what’s best hmmph.
jimdubleyouFull MemberThere are many programmers who will spend ages crafting something clever pants when it’s not what’s actually needed or what’s best.
It’s twice as hard to debug something as it is to write it. So if you’re as clever as you can be when you write it, how are you ever going to debug it?
(C) Some lecturer at uni. Forget his name now. He was a bit of a nutter though
rossburtonFree MemberPerl being a good example of this taken to extreme, where variables can be implicit so complex loops can be very concisely written but actually understanding what they do from scratch is almost impossible.
(when I was young and innocent I wrote a tool for work in perl, went back to it a year later and after a week of staring at the code to try and fix a bug, gave up and rewrote it all in clear Python)
footflapsFull MemberPerl being a good example
Or regex / sed…
Found this gem today which I’ve incorporated into some tools…
sed -r ‘:r; s/(“[^”,]+),([^”,]*)/\1 \2/g; tr; s/”//g’
molgripsFree MemberThose irritating users who think they know better what’s needed or what’s best hmmph.
I’m not advocating listening to them either 🙂
The number of people in this business who take the requirements as gospel is quite astounding. When if something is really problematic you can go back to them and ask how important that bit really is, and they often say ‘oh, it’s not important, we just tossed that in cos we thought it would be cool but don’t worry’.
I must’ve saved millions that way 🙂
mrmonkfingerFree MemberShared!
Liked!
Godawful code by the way.
I’d send it back for rewriting.
And likely not re-hire any dev pulling that kind of tosh on my watch.
mrmonkfingerFree Membersed -r ‘:r; s/(“[^”,]+),([^”,]*)/\1 \2/g; tr; s/”//g’
no quotes and commas for you young man
GrahamSFull Membersed -r ‘:r; s/(“[^”,]+),([^”,]*)/\1 \2/g; tr; s/”//g’
An old programmer’s proverb:
Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.But if you think that is confusing (and it really isn’t once you can read regex) then try this:
•ø6ŒY2l½î€ÈS`L<eÆô‚˜3ª½¨ºE»D2Âô3•b15ô1«vy€D„# è¹×,
Any guesses what that code does? It is written in a language called 05AB1E
mrmonkfingerFree MemberI see you’re a fan of obfuscated code.
Noted for future reference.
skidsFree Memberhere is a good free Python book that the author has made available as a web site,
https://automatetheboringstuff.com/GrahamSFull MemberI see you’re a fan of obfuscated code.
It was a Code Golf answer from here:
http://codegolf.stackexchange.com/questions/95268/lets-draw-some-atari-st-bombsrossburtonFree MemberFound the quote about debugging:
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you’re as clever as you can be when you write it, how will you ever debug it?
Brian Kernighan, “The Elements of Programming Style”, 1974.
oldnpastitFull MemberEveryone knows that debugging is twice as hard as writing a program in the first place. So if you’re as clever as you can be when you write it, how will you ever debug it?
That may explain a lot about C++….
jimdubleyouFull Member(C) Some lecturer at uni.(C) Brian Kernighan as ripped off by some lecturer at uni.
It was a C class though, so the lecturer must have read the book 😛
footflapsFull Memberno quotes and commas for you young man
Not quite; no commas inside quotes. I wanted it for parsing CSV when there are commas inside quotes and I’m using cut to split up the CSV by column….
Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.
yes, I normally leave a comment next to it with an explanation and a link to the web page I nicked it from (normally Stack Overflow) as I’ll never work out what it does when I come back to it next month….
polyFree MemberThey say that a basic knowledge of programming is required and if you understand the following question it’s a good test:
a = b = c =’Arista’
Presumably the test is to point out “that isn’t a question”…TheBrickFree Membersed has claimed days of my life. I too now just use python, even though I probably don’t do everything in the correct “python” way, it works, and I can read it.
sirromjFull MemberI find this site really helpful for figuring out regex
https://regex101.comIt’s also quite helpful to use input which conforms with expectations, as I discovered today after spending rather a long time completely baffled as why regexes in Windows Powershell seemed to work differently to Linux.
footflapsFull MemberRegex is bad enough in Linux, eg Expect has a different syntax to Bash…..
mrmonkfingerFree MemberNot quite; no commas inside quotes. I wanted it for parsing CSV when there are commas inside quotes and I’m using cut to split up the CSV by column….
Huh. Should remove all quotes with the final s/
Label r
First s/ removes the first comma inside a quote.
If matched, (tr) jump back to r – do another comma.
Next s/ global substitute all quote for nothing.footflapsFull MemberHuh. Should remove all quotes with the final s/
Yep, you’re right!
sed -r ‘:r; s/(“[^”,]+),([^”,]*)/\1 \2/g; tr; //g’
Does what I thought wanted (although both work as I don’t care about quotes).
I doff my Regex cap to you..
Your post is now hyperlinked in my source code 😉
TurnerGuyFree MemberThat’s nonsense, tbh.
except that it was a quote from a university lecturer saying how hard it was to predict who was going to be a good programmer from his intake every year.
He reckoned that those whose immediate reaction to an assignment expression like this was that it was not logically correct were less likely to make good programmers than those who identified its alternate meaning in a computer language context.
And crafting clever solutions can be valid if it reduces the overall amount of code written, as there is a metric stating the average number of bugs per line of code.
It’s a balancing act and the complexity can be mitigated to a large extent by writing test cases that publish assertions about how the code works, as well as protect against programmers tinkering with it to effect quick fixes.
Brian Kernighan, “The Elements of Programming Style”, 1974.
not sure that book is even in C, I think it might be Fortran and the like. I will check tonight ( 🙂 ).
The other one around at the time “Programming Tools” was originally in ratfor, which was a C like preprocessor that produced Fortran.
molgripsFree MemberAnd crafting clever solutions can be valid if it reduces the overall amount of code written, as there is a metric stating the average number of bugs per line of code.
There’s some flawed logic right there. If you can get the average number bugs per line down a lot, then increasing the number of lines a bit will still result in fewer bugs.
And in my opinion compressing code using shorthand like that is much more likley to introduce bugs. Code should be structured in such a way that each method should be so trivial bugs are unlikely and obvious.
TurnerGuyFree MemberThere’s some flawed logic right there. If you can get the average number bugs per line down a lot, then increasing the number of lines a bit will still result in fewer bugs.
read that back to yourself…
No-one said anything about compressing the code – maybe the smart identification of some interfaces and applying generics for example could cut down the amount of code written by a long way.
Templates in C++ is another way allowing ‘compile time polymorphism’ – the Fix engine I wrote made extensive use of templating to define generic processing pipelines (pipes and filters) and common treatment of message formats and translation to SP calls that meant I could cut down the amount of code I wrote by a long way.
Code should be structured in such a way that each method should be so trivial bugs are unlikely and obvious.
Several people are pointing out that the more people are decomposing things down into trivial ‘units’ like this, combined with polymorphism, the harder it is to track what the code is doing by inspection.
Again, its a balancing act.
Best way to think about it is to consider that you might have to come back to the code after 6 months on another project and have to pick it back up again, therefore you should structure the solution to be as comprehensible as possible.
Personally I like the idea of asserting unit/integration tests that make ‘statements’ about how the system works.
But again there is a balancing act between writing copious amounts of tests and locking down a system such that is very hard to refactor new functionality in or to evolve the architecture.
Automatic system level tests rather than loads of unit tests seem to be more appropriate to counter this, and to avoid wasting time testing areas of the code that are never exercised.
jimdubleyouFull MemberSeveral people are pointing out that the more people are decomposing things down into trivial ‘units’ like this, combined with polymorphism, the harder it is to track what the code is doing by inspection.
This is where naming your procedures come in though:
…If AReallyComplicatedThingIsTrue() then…
AReallyComplicatedThingIsTrue() can have any number of other procedures to decide if it’s true or not and you need to decide what level you need to go to when trying to work out what the program as a whole does.*
* I used to write RPGLE for a living, your syntax may very 😛
therefore you should structure the solution to be as comprehensible as possible.
Totally agree with this. We ask for for accurate, maintainable, efficient code (in that order) from our programmers. The first two are a minimum, ideally you’ll get all three.
TheBrickFree MemberDon’t get dogmatically tied to any of these solutions. Take what works for the project
The topic ‘One for the programmers’ is closed to new replies.