Programming long script gets extremely slow
7 次查看(过去 30 天)
显示 更早的评论
Hi, im currently writing a script in R2016a. It is 18k lines long right now, and it's done for about 25%. However, the programming gets really slow right now (it did since about 12-15k lines). The running of the script goes just fine, but when I try to edit it it severely lags: whatever I type into the code takes several seconds to actually appear. Does anyone else have similar experience with this issue and an idea on how to fix it? Thanks a lot!
3 个评论
Stephen23
2017-5-18
72000 lines of code in one file... ouch! That sounds impossible to write correctly, and impossible to debug. Why not just use the simple methods that everyone else uses: split code into functions, write OO code, make sure that is is vectorized and follows the other good MATLAB practices... ?
Adam
2017-5-18
I'm highly uncomfortable with one of my GUIDE m-files that is 1320 lines long and that even includes lots of lines of automatically created stuff. I can't imagine writing even a function tens of thousands of lines long, let alone a script!
采纳的回答
Jan
2017-5-18
Of course writing such a huge M-file in Matlab's editor is slow. It is expected to be. Note that the editor performs a syntax check after all changes, can highlight code blocks, variables, checks if opening and closing brace, brackets or parenthesis have to be highlighted, checks the indentation of for and while loops and let MLint check the validity and efficiency of the code.
Functions or even worse scripts with more than 1000 lines of code are hard to read and to maintain. It gets horrible to debug this code and you cannot apply unit tests to parts of it. Therefore the complexitiy of the code will be such high, that an exhaustive testing is impossible. In consequence no serious programmer would use such code, but delete it without any further investigations.
Split the code to subfunctions. This will improve the editing, maintenance and perhaps even the runtime.
4 个评论
Adam
2017-6-1
How can you possibly even understand code that long. Being able to edit it seems like rearranging deckchairs on the Titanic compared to the problem of maintaining it as working code.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!