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

This User Gave Thanks to MadeInGermany For This 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
These 4 Users Gave Thanks to bakunin For This 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.
This User Gave Thanks to Corona688 For This Post:
MadeInGermany (06-08-2017)
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
HTTP coding shorty Shell Programming and Scripting 5 06-24-2015 06:11 PM
Need help with coding crazydude80 Windows & DOS: Issues & Discussions 2 03-26-2012 07:29 PM
Need help with coding crazydude80 Shell Programming and Scripting 1 03-26-2012 07:25 PM
Naive Bayes gizmo87 Homework & Coursework Questions 0 11-15-2011 07:56 PM
Coding in Phyton kristinu Shell Programming and Scripting 3 11-28-2010 10:37 PM
need help for coding this logic suprithhr AIX 1 08-14-2008 03:34 PM
pro*c coding user71408 UNIX for Dummies Questions & Answers 1 03-25-2008 06:52 AM
Coding on my Mac DKNUCKLES Shell Programming and Scripting 1 11-28-2007 04:35 AM
can I use this coding w33man UNIX for Advanced & Expert Users 6 03-02-2004 08:49 AM
All times are GMT -4. The time now is 05:36 PM.

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





Not a Forum Member?
Forgot Password?