5 Replies - 816 Views - Last Post: 16 April 2016 - 05:45 PM

#1 leibniz76   User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 89
  • Joined: 02-May 14

What can I do to prevent my program from getting out of control?

Posted 16 April 2016 - 01:27 PM

I've got a program written in Python of 5300 lines. After 4 months I'm finally at the point where I can get the program to do what I want. What it does is it determines if a sentence written in natural English is contradictory or consistent. The code will never be finished, only gradually improved so I now need to start thinking about what I can do prevent the code from getting out of control. I read once on this forum that a programmer let their code get out of control and someone else had to be brought in to fix things up. I don't want that to happen to me. Also, before I wrote this code I was working on artificial languages and things did eventually get a point where they were too cumbersome and the code was too brittle and I had to junk it and start over from scratch. I don't want that to happen again. One thing I've seemed to have learned is I keep the global section of the code very small. Right now, the global section is just 80 lines, the other 5220 lines of the code is functions. That really helps. Any other advice would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: What can I do to prevent my program from getting out of control?

#2 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6659
  • View blog
  • Posts: 30,976
  • Joined: 10-May 07

Re: What can I do to prevent my program from getting out of control?

Posted 16 April 2016 - 01:32 PM

without being able to see your code, I'm going to just go with some generics :
1.) Write reusable code, functions,
2.) Write cleaner code (switch case in place of if/else if/else if/else if)
3.) Use standard libraries instead of home-brew solutions
4.) Split your code form a single file into multiple files & include the additional files
Was This Post Helpful? 0
  • +
  • -

#3 leibniz76   User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 89
  • Joined: 02-May 14

Re: What can I do to prevent my program from getting out of control?

Posted 16 April 2016 - 01:45 PM

View Postno2pencil, on 16 April 2016 - 01:32 PM, said:

3.) Use standard libraries instead of home-brew solutions

I'm guessing that this means use function already written rather than ones you create.

Quote

4.) Split your code form a single file into multiple files & include the additional files

I don't know what this means.
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11135
  • View blog
  • Posts: 19,079
  • Joined: 19-March 11

Re: What can I do to prevent my program from getting out of control?

Posted 16 April 2016 - 03:37 PM

View Postno2pencil, on 16 April 2016 - 03:32 PM, said:

2.) Write cleaner code (switch case in place of if/else if/else if/else if)


In python, there's no switch though you could probably implement one. The better bet is usually a dictionary.


Quote

What it does is it determines if a sentence written in natural English is contradictory or consistent.


This problem is in many ways similar to that of compiling a programming language, only somewhat more difficult because it's impossible. I would recommend that you at least acquire a good compilers textbook and try to get an understanding of how that job is typically done, and use that to think about how you should be structuring your code for this project. Taking a compilers course would not be a bad plan, if you can manage it. It might or might not help you with your current project, but it'll certainly teach you a lot.

Since you're working in python, I would also point you to the Natural Language Toolkit, which has a lot of useful libraries for parsing natural languages like English.

View PostChrysippus, on 16 April 2016 - 03:45 PM, said:

Quote

4.) Split your code form a single file into multiple files & include the additional files

I don't know what this means.


This means that it is better to have 53 files of 100 lines each than to have one file of 5300 lines. You may already be doing this.
Was This Post Helpful? 1
  • +
  • -

#5 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6659
  • View blog
  • Posts: 30,976
  • Joined: 10-May 07

Re: What can I do to prevent my program from getting out of control?

Posted 16 April 2016 - 05:29 PM

View Postjon.kiparsky, on 16 April 2016 - 06:37 PM, said:

View Postno2pencil, on 16 April 2016 - 03:32 PM, said:

2.) Write cleaner code (switch case in place of if/else if/else if/else if)


In python, there's no switch though you could probably implement one. The better bet is usually a dictionary.

Maybe that's so, perhaps member should have posted in a proper sub-forum for a more accurate answer. Having been that I've only coded 1 application in Python, I would have had no business replying, except OP posted in Corner Cubicle, which is "work related".
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky   User is online

  • Beginner
  • member icon


Reputation: 11135
  • View blog
  • Posts: 19,079
  • Joined: 19-March 11

Re: What can I do to prevent my program from getting out of control?

Posted 16 April 2016 - 05:45 PM

Oh, no criticism intended. Just wanted to clarify that that particular control structure is not available in this case.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1