Home Man
Search
Today's Posts
Register

Discuss whatever is on your mind. New members can introduce themselves. Talk or comment about any topic that's on your mind..

Naive coding...

Tags
discussion, discussions, software development

👤 Login to reply

 
Thread Tools Search this Thread
# 8  
Old 02-22-2017
Two corrections:
Code:
case "$STR" in 
"") echo "Blank" ;;
*[!0-9]*)  echo "Contains non-numeric" ;;
*) echo "Valid" ;;
esac

The Following User Says Thank You to MadeInGermany For This Useful Post:
Corona688 (02-22-2017)
# 9  
Old 03-05-2017
A few observations about programming habits and programming in general:

I think the real difference between naive and non-naive (clever) programming is not so much to make (or make not) use of a certain language construct but the employment of certain algorithms. The example of Corona688 shows that very clearly. The difference in simplicity (and perhaps speed) comes not from using some "clever language feature" a non-expert might not know about, but from the ability to look at the problem from a different angle and draw the right conclusion.

Here is a story from my own practice: I once worked for a development team who created some database application. At one time they had trouble with a daily import routine because it ran approximately 32 hours. (For the non-experts: standard days come with only 24 of them. ;-) ) The import script worked like that: first a huge SQL-statement to create some table. This table was fed into a loop where something was changed, then the whole was fed back into the DB. The script looked like this (only the structure):

Code:
#! /bin/ksh

db2sql "...some 300 lines of SQL here...." |\
while read record ; do
     newrecord=$(echo $record | sed '....some changing of the record here....')
     db2sql "... import record from $newrecord here..."
done

exit 0

There is nothing "logically wrong" here and when you test it with 5 records it is probably as fast as any other solution. Doing it with some ten-million-records table, though, will reveal that calling sed one time for every record is slightly slower (by several orders of magnitude) than to call it once in a pipeline:

Code:
db2sql "...some 300 lines of SQL here...." |\
sed '....some changing of the records here....' |\
while read newrecord ; do
     db2sql "... import record from $newrecord here..."
done

So, this was my first instinctive comment and (we tested it later) it would have brought down the processing time by ~3.5 hours. But i worked on this together with the DBA and he observed inside the 300-line-SQL-monster (which i had ignored, being an SQL-ignorant) that most of it was effectively creating a left outer join of the whole database on itself and then dropping 99% of it, So, after selecting what really was to be selected - and finding out that the changes could be done inside instead of using the shell and an external program to do it - - we arrived at:

Code:
db2sql "select for update ...some 20 lines of SQL here...."

which took - about 5 seconds. All the while management was calling for bigger hardware to "meet increasing needs" instead of just firing this incompetent click-boy who confused some graphic representation of the DB within a tool (Informatica) with reality.

So, what is the differrence between clever and naive programming? It is about the same difference as 32 hours and 5 seconds.

My two cents.

bakunin
The Following 4 Users Say Thank You to bakunin For This Useful Post:
Corona688 (03-06-2017), Don Cragun (03-05-2017), ni2 (04-08-2017), zaxxon (03-06-2017)
# 10  
Old 05-24-2017
I wrote a rather naive snake implementation... it worked by each position being logged in an array... so each time you move a for loop scanned the array for collisions it would take a little longer. The target machine was a 50Mhz Sparcstation LX so... I thought nothing of it when writing it but it became obvious when running the game. After about 100 indexes it would get so slow you could just about walk away and get coffee, perhaps I exaggerate a bit but still! Rather than using an array of previous positions, I probably should have allocated an array the size of the play area and marked them traversed or not.
# 11  
Old 05-25-2017
Why was it looped? If you know where the snake is and where it's going, there's only one cell to check.
The Following User Says Thank You to Corona688 For This Useful Post:
MadeInGermany (06-08-2017)
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
php: Need little help in Coding AimyThomas Programming 2 09-26-2012 07:51 AM
Need help with coding crazydude80 Windows & DOS: Issues & Discussions 2 03-26-2012 06:29 PM
Need help with coding crazydude80 Shell Programming and Scripting 1 03-26-2012 06:25 PM
Naive Bayes gizmo87 Homework & Coursework Questions 0 11-15-2011 06:56 PM
pro*c coding user71408 UNIX for Dummies Questions & Answers 1 03-25-2008 05:52 AM
sed coding rita1985 UNIX for Dummies Questions & Answers 1 01-28-2008 11:23 PM


All times are GMT -4. The time now is 02:07 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password