How to can I increase my code readability in C#

  • Thread starter Thread starter Osama Rajab
  • Start date Start date
O

Osama Rajab

Hi Guys,
When I skim fast into my old code or others code, I
forget what the type of a certain variable was or what
its initialization value was.

We use the Hungarian notation and it helps to remember
what was the type (most of the times), but it dose not
help to know what was the initialization value. Even with
Hungarian notation some time the prefix gets the same for
deferent types.

Now VB.Net players use Dim Key word in the line that
contains the variable definition, and as long Dim is a
key word it appears in blue color and that helps a lot to
locate it very fast. I try to add /**/ just before each
variable, it helps a lot to locate the lines, but as long
it's not a language standard that has a lot of problems...

Although we have the "goto definition" in the IDE;
thanks Microsoft it helps a lot; it dose not help with
the locating the initialize value. Also "goto definition"
has a problem which I call it "Uncontrolled Move", I mean
you may jump far away from your code point and that lost
your focus of what you was reading to locating your code
point again....

If any body has an idea of how to solve these problems
please help.. or if any body know if there is a window
like the "Autos" window which we have in Debug time that
run in the design time....

Best Regards,
Osama Rajab
 
I probably can't offer you much help, seeing as I don't even use the
type-identifying prefixes (like 'str' and 'int', etc.). I also don't find
my code (or anyone else's code written in the same manner) confusing either.
But I'm not one to criticize anyoneone's coding style, it's largely a
personal preference thing. One thing I can suggest is that you use
bookmarks to navigate through your code more efficiently. Before you use
'go to definition', just set a bookmark wherever you are, and with just one
click, you're back where you started. I have found that .NET's 'go to
definition' is less useful than VB6's ever was simply because I can mouse
over a variable name, and get most of the information I need right there.
It tells you the type, whether it's public or private, where it came from
(e.g. local variable, parameter, etc.). I don't know why the init value is
of interest, but I suppose some fancy comment next to where the variable is
initialized would be sufficient enough to quickly find it.

Chris LaJoie
 
Osama Rajab said:
When I skim fast into my old code or others code, I
forget what the type of a certain variable was or what
its initialization value was.

So hover over the variable and you should find its type very quickly.
We use the Hungarian notation and it helps to remember
what was the type (most of the times)

Hovering is likely to be more accurate.
but it dose not
help to know what was the initialization value. Even with
Hungarian notation some time the prefix gets the same for
deferent types.

Which is why I don't use Hungarian... (well, one reason, anyway).
Now VB.Net players use Dim Key word in the line that
contains the variable definition, and as long Dim is a
key word it appears in blue color and that helps a lot to
locate it very fast. I try to add /**/ just before each
variable, it helps a lot to locate the lines, but as long
it's not a language standard that has a lot of problems...

If your methods are small enough, the local variable declarations
should be fairly obvious. Give XML documentation to non-local variables
and it should be easy enough to find them. You might also want to
Although we have the "goto definition" in the IDE;
thanks Microsoft it helps a lot

I just wish MS would implement the same system Eclipse has, where
holding down Ctrl makes variables (and method names etc) into links,
and clicking the link takes you to the definition - much easier than
going for a context menu etc. Other key modifiers can make the
hover/link do different things. It's a really nice feature.
it dose not help with
the locating the initialize value.

Only if you don't initialise the value at the declaration - and if you
don't, they could be initialised at any number of places. I'm not sure
what you want here...
Also "goto definition"
has a problem which I call it "Uncontrolled Move", I mean
you may jump far away from your code point and that lost
your focus of what you was reading to locating your code
point again....

That's what the "back" button is for though. It's the one next to the
"Redo" button, at least by default. Press Ctrl and Minus at the same
time and you should get the same effect too.
If any body has an idea of how to solve these problems
please help.. or if any body know if there is a window
like the "Autos" window which we have in Debug time that
run in the design time....

I can't say it's something that's ever bothered me. If you know the
initialisation value in advance, put it in with the declaration. If
not, I don't see how the IDE could work it out. You can always write
something in the XML documentation, and that will pop up when you hover
over the variable name.
 
Hi John,
Can you please explain to me the Hover method or send
me any link about it...
local variables
I don't know XML documentation ,can you help ???
The point is, the variable could be initialized at any
point other than the declaration line, so locating the
initialization line some times defficult. I want to
remind you that the code I read dose not belong to me or
some one in my team.

Osama Rajab
 
[Post reformatted for readability]

Osama Rajab said:
Can you please explain to me the Hover method or send
me any link about it...

Just hover your pointer over a variable name. You'll see its type and
any documentation you've written for it.
I don't know XML documentation ,can you help ???

Look up "XML documentation" in MSDN - if you're not using it, then
becoming aware of it and using it extensively is the first step towards
greater readability, IMO.
The point is, the variable could be initialized at any
point other than the declaration line, so locating the
initialization line some times defficult.

Right. That sounds like you want the "usage" search in Eclipse, which
shows when fields are read/written/declared. Unfortunately I don't know
of anything similar in VS.NET :(

(Note that a write doesn't necessarily mean initialisation - it could
be reassignment.)
I want to
remind you that the code I read dose not belong to me or
some one in my team.

Ah... that certainly makes things harder.
 
Back
Top