I'm rewriting my code around 10 times before f

2019-04-06 14:36发布

When i start writing something complex, I find that restart the writing like 10 times before I end up with what I want, often discarding hundreds of lines of code.

Am I doing something wrong, or do others have workflows like this?

EDIT: Right now, I'm working on a modular compiler. The last project I was working on was a server in java. Before that it was some concurrency stuff.

I do a fair bit of planning, and I never start coding before I've got interfaces for everything.

Given that, is it normal to just wipe the slate clean repeatedly?

标签: workflow
13条回答
Melony?
2楼-- · 2019-04-06 15:31

Discarding many lines of code is usually a positive aspect of refactoring. That's great. But starting over ten times means that you probably haven't analyzed your problem and solution. It's fine to backtrack and sometimes to start over but not that often. You should lay out your code in such a way that when you backtrack and refactor, you keep most of what you created because it will exist in nicely isolated and logical chunks. (Using vague language since language of choice wasn't specified.)

From author's comment:

Usually I restart because I get confused by all the stuff going on in my code.

Study your craft and make good use of design patterns and other best programming philosophies to lend your code a well-defined structure... something you'll recognize months and even days down the road.

查看更多
等我变得足够好
3楼-- · 2019-04-06 15:32

Perfectly normal. No matter how much I plan ahead, I very often have an "Aha!" moment once the hands hit the keyboard.

Just as often it's a "What the heck was I thinking?" moment.

It's all good. You're making better code.

查看更多
forever°为你锁心
4楼-- · 2019-04-06 15:33

If you're starting something complex, a little planning before you start writing would seem to be a good idea.

Design first.

查看更多
闹够了就滚
5楼-- · 2019-04-06 15:37

On a complex problem, this is common. If you aren't totally stabbing in the dark, it really helps to sketch out our ideas first, but then again you're just moving the 'retries' from code to paper.

If it helps you get to a good solution, how can it be wrong?

查看更多
孤傲高冷的网名
6楼-- · 2019-04-06 15:37

Compilers are very complex applications, and you can't write an optimizing compiler from start to finish in one pass - no matter how much thought you put into it at first. Usually you attempt to get something to work correctly from start to finish and then go back to modularizing it and adding new features like optimizations. This process means lots of refactoring and replacing whole sections outright. This is also part of the learning processes - as no one can know everything and remember it!

(I'm also working on a .NET compiler as part of the MOSA project - www.mosa-projet.org.)

查看更多
成全新的幸福
7楼-- · 2019-04-06 15:37

It's called refactoring buddy and it's good, you just need to limit it so you won't end up wasting all your time refactoring code you have and is working instead of writing new code.

Some of the reasons why one must refactor are:

  • Enhancing performance.
  • Organizing code.
  • You need to write your code in a different way to get something to work.
  • To do something in a different way because it saves a lot of work (i.e.: Using MXML instead of ActionScript).
  • You used the wrong name for a variable.
查看更多
登录 后发表回答