using classes vs. modules

  • Thread starter Thread starter Andy B.
  • Start date Start date
Hello Michael,
I noticed both you or Herfried snipped my point about pointers and
unsafe code. If VB is aimed at pros then why is it missing "the"
biggest pro feature of all time?

Because greater than 99% of programmers (beginner or pro) don't need them.
 
Michael C said:
If it's aimed at beginners and professionals they why didn't they add
pointers to VB?

Unsafe pointers are no "professional" feature. Today they are just a
feature which is used in very special domains (low-level development, which
is typically done using C) and in interop scenarios in order to access
legacy libraries and code (such as COM components and other unmanaged APIs).
In user-mode development (.NET has been designed for that) unsafe pointers
are really unimportant.
The beginners don't need to use the pointers so it doesn't cause them any
trouble but the experts can still use them. Same goes with the yield
return keyword, writing your own linq extensions is a slightly advanced
topic which they thought was not necessary for beginners.

Same goes with 'When' clauses in 'Try...Catch' blocks, same goes with event
support as provided by VB, same goes with language-integrated XML features,
....

Sorry, the actual feature set doesn't have a significant influence on wether
or not a language is suitable for beginners and/or professionals.

Actually I have seen C# developers struggling with p/invoke function
declarations involving unsafe pointers although the exact same result could
have been achieved by safe code.

Once simple Windows applications have been written in C using pointers and
the Win32 API. On the other hand, other people used VB for this purpose and
didn't need pointers at all to achieve almost equal results. Which way
would you consider more professional?
Pretty much, the pro does not need the comfort of all the extra words,
it's just unecessary and slows them down.


I noticed both you or Herfried snipped my point about pointers and unsafe
code. If VB is aimed at pros then why is it missing "the" biggest pro
feature of all time?

VB is a secure and high-level programming language for development of
applications for the user mode.

In which cases are you still using unsafe pointers? Just give some
examples, but do not list any interaction with legacy technologies (native
libraries, COM, ...). BTW, I am aware that pointers are sometimes used for
direct access to bitmap data, but this is a really special case in which I'd
consider writing a class library using C++/CLI or maybe C#.
 
Rory Becker said:
Hello Michael,


Because greater than 99% of programmers (beginner or pro) don't need them.

So you're saying that 1% of programmers have used pointers. That is simply
rubbish.

Michael
 
Herfried K. Wagner said:
Unsafe pointers are no "professional" feature.

Come on Herfried, they are "THE" professional feature. They are certainly
something a beginner would struggle with.
Today they are just a feature which is used in very special domains
(low-level development, which is typically done using C) and in interop
scenarios in order to access legacy libraries and code (such as COM
components and other unmanaged APIs). In user-mode development (.NET has
been designed for that) unsafe pointers are really unimportant.

That's really not true. For something as simple as bitmap manipulation you
need to use pointers. This isn't exactly an obscure a feature. The framework
even has a method (Bitmap.LockBits) that returns you a pointer. I get the
impression that a lot of VBers think that unsafe code is like a bomb, ready
to go off at any moment, highly unstable and difficult to handle. Really,
unsafe code is just a way of saying to the compiler "I have double checked
and tripled checked this code so you don't need to run all the normal checks
because I've done them".
Same goes with 'When' clauses in 'Try...Catch' blocks, same goes with
event support as provided by VB, same goes with language-integrated XML
features,

Not really, these are not advanced features.
Sorry, the actual feature set doesn't have a significant influence on
wether or not a language is suitable for beginners and/or professionals.

Actually I have seen C# developers struggling with p/invoke function
declarations involving unsafe pointers although the exact same result
could have been achieved by safe code.

I've seen very capable developers in VB too. I might not be the best
developer in the world but I have been coding full time for the last 10
years. When I moved over to C# I realised it was more aimed at people like
me.
Once simple Windows applications have been written in C using pointers and
the Win32 API. On the other hand, other people used VB for this purpose
and didn't need pointers at all to achieve almost equal results. Which
way would you consider more professional?

Depends on the situation. Using the wrong language is something I would
considered unprofessional.
VB is a secure and high-level programming language for development of
applications for the user mode.

In which cases are you still using unsafe pointers? Just give some
examples, but do not list any interaction with legacy technologies (native
libraries, COM, ...).

I have used them for bitmap and video manipulation.
BTW, I am aware that pointers are sometimes used for direct access to
bitmap data, but this is a really special case

It's not really that special a case. You could use this to make a bitmap
looked grayed out in a webpage. I actually use it for every bitmap I open
from a file. In dot net for some reason the bitmap you open is always tied
to the file you opened it from. Nothing I could find could unlock this
association, even using Bitmap.Clone had problems. My solution was to open
the bitmap, create a second bitmap of equal size and use pointers to copy
the data from one bitmap to another. This way you got a bitmap which was
completely independant of the file. In Paint.Net (a free paint program which
was assisted by some MS programmers) they went one step further and defined
their own buffers for every bitmap (using GlobalAlloc i think) and then
associated that buffer with the bitmap object.
in which I'd consider writing a class library using C++/CLI or maybe C#.

If you're using C# then there is no reason to step out to C++, you can just
write the code inline. It works really well. I get the impression you're a
good programmer so I imagine you'd quite enjoy using pointers.

Michael
 
Hello Michael,
So you're saying that 1% of programmers have used pointers. That is
simply rubbish.

Yeah you're right.... These days it's probably far lower than that :)

Seriously, when it comes to the dotnet framework at least, there are very
few reasons to use pointers.

Most apps written for the .Net framework are LOB apps, which use winforms
or ASP.Net there is simply no need for pointers in these cases.
 
Rory Becker said:
Yeah you're right.... These days it's probably far lower than that :)
Hardly.

Seriously, when it comes to the dotnet framework at least, there are very
few reasons to use pointers.

Actually there are many reasons, you are probably just not aware of them.
Most apps written for the .Net framework are LOB apps, which use winforms
or ASP.Net there is simply no need for pointers in these cases.

As I said to Herfriend, even graying out a bitmap in a webpage can use
pointers. If you do any reasonable amount of work with bitmaps then their
use will come up and obviously bitmap use is common these days. In VB can
you can copy the data from the bitmap to an array and back (line by line
usually) but this is just as unsafe as unsafe code.

Michael
 
Michael C said:
Actually there are many reasons, you are probably just not aware of them.


As I said to Herfriend, even graying out a bitmap in a webpage can use
pointers.

It could, but a professional developer would not write his own
"convert-to-grayscale" routine #212,434,239. Instead he would use a
high-level graphics package.
 
Michael C said:
Come on Herfried, they are "THE" professional feature. They are certainly
something a beginner would struggle with.

Pointers are not that hard to understand. However, they are typically
unsafe, cannot be checked at compile time, and can thus increase the
potential for bugs in the code and exploitation.

I doubt that a beginner would struggle more with pointers than with OOP.
That's really not true. For something as simple as bitmap manipulation you
need to use pointers. This isn't exactly an obscure a feature. The
framework even has a method (Bitmap.LockBits) that returns you a pointer.
I get the impression that a lot of VBers think that unsafe code is like a
bomb, ready to go off at any moment, highly unstable and difficult to
handle. Really, unsafe code is just a way of saying to the compiler "I
have double checked and tripled checked this code so you don't need to run
all the normal checks because I've done them".

I've said you do not need to mention bitmap manipulation as I have already
mentioned it.
Not really, these are not advanced features.

What do you consider "advanced"?
I've seen very capable developers in VB too. I might not be the best
developer in the world but I have been coding full time for the last 10
years. When I moved over to C# I realised it was more aimed at people like
me.

Well, then just be happy that you have found what you are looking for.
Tastes are different and VB is not the same as C#.
Depends on the situation. Using the wrong language is something I would
considered unprofessional.

One of the very rare occasions of agreement...
It's not really that special a case. You could use this to make a bitmap
looked grayed out in a webpage. I actually use it for every bitmap I open
from a file. In dot net for some reason the bitmap you open is always tied
to the file you opened it from. Nothing I could find could unlock this
association, even using Bitmap.Clone had problems. My solution was to open
the bitmap, create a second bitmap of equal size and use pointers to copy
the data from one bitmap to another.

Why not just use this (conceptional) code?

\\\
Dim OriginalImage As New Bitmap("C:\WINDOWS\Angler.bmp")
Dim Image As New Bitmap(OriginalImage)
OriginalImage.Dispose()
....
Image.Dispose()
///
If you're using C# then there is no reason to step out to C++, you can
just write the code inline.

.... only as long as C# is sufficient. There are some things which cannot be
done in C# though. So the level of "breaking out to use C/C++" is just
different between VB.NET and C#, but it only differs slightly between the
two programming languages.
It works really well. I get the impression you're a good programmer so I
imagine you'd quite enjoy using pointers.

I used pointers for years in C, which is one of my favorite programming
languages beside BASIC-style languages.
 
Rory said:
Hello Michael,


Yeah you're right.... These days it's probably far lower than that :)

Seriously, when it comes to the dotnet framework at least, there are
very few reasons to use pointers.

Most apps written for the .Net framework are LOB apps, which use
winforms or ASP.Net there is simply no need for pointers in these cases.

Michael must think that there are no professional Java programmers either.

The simple fact is that the pointer data type is not required - in VB or
Java (or many other languages).

Here's what Sun says about pointers:

"Most studies agree that pointers are one of the primary features that
enable programmers to inject bugs into their code. Given that structures
are gone, and arrays and strings are objects, the need for pointers to
these constructs goes away. Thus, Java has no pointer data types. Any
task that would require arrays, structures, and pointers in C can be
more easily and reliably performed by declaring objects and arrays of
objects. Instead of complex pointer manipulation on array pointers, you
access arrays by their arithmetic indices. The Java run-time system
checks all array indexing to ensure indices are within the bounds of the
array.

You no longer have dangling pointers and trashing of memory because of
incorrect pointers, because there are no pointers in Java."
 
Hello Michael,
As I said to Herfriend, even graying out a bitmap in a webpage can use
pointers. If you do any reasonable amount of work with bitmaps then
their use will come up and obviously bitmap use is common these days.
In VB can you can copy the data from the bitmap to an array and back
(line by line usually) but this is just as unsafe as unsafe code.

Even a half competent programmer knows to use the right tool for the right
job.

Low level pointer work ???? For greying out a graphic on a web page???
I don't know what you're smoking but I guess it's good.

I wonder how many other things look like a nail for your pointer hammer.

For the record CSS/Jquery is a far better bet, or if that's efficient enough,
any suitable paint package would be suitable for a one off conversion and
then switch at runtime as appropriate.
 
Herfried K. Wagner said:
It could, but a professional developer would not write his own
"convert-to-grayscale" routine #212,434,239. Instead he would use a
high-level graphics package.

What happens if you don't have the bitmap until runtime? ie user supplied
bitmap.

Michael
 
Rory Becker said:
Even a half competent programmer knows to use the right tool for the right
job.

Low level pointer work ???? For greying out a graphic on a web page???
I don't know what you're smoking but I guess it's good.

I wonder how many other things look like a nail for your pointer hammer.

Perhaps you think pointers are more scary/dangerous than they really are. To
me they are no big deal, if I need to go through some data at high speed
then use a pointer. You can't get much more of a perfect example than
modifying an entire bitmap.
For the record CSS/Jquery is a far better bet, or if that's efficient
enough, any suitable paint package would be suitable for a one off
conversion and then switch at runtime as appropriate.

What happens if you don't have the bitmap until runtime?
 
Jason Keats said:
Michael must think that there are no professional Java programmers either.

I didn't say that there are no professional VB programmers, just than VB is
aimed at beginners.
The simple fact is that the pointer data type is not required - in VB or
Java (or many other languages).

Here's what Sun says about pointers:

"Most studies agree that pointers are one of the primary features that
enable programmers to inject bugs into their code. Given that structures
are gone, and arrays and strings are objects, the need for pointers to
these constructs goes away. Thus, Java has no pointer data types. Any task
that would require arrays, structures, and pointers in C can be more
easily and reliably performed by declaring objects and arrays of objects.
Instead of complex pointer manipulation on array pointers, you access
arrays by their arithmetic indices. The Java run-time system checks all
array indexing to ensure indices are within the bounds of the array.

You no longer have dangling pointers and trashing of memory because of
incorrect pointers, because there are no pointers in Java."

What a complete load of total and utter rubbish. Thinking like this is why
Java is so slow. In C# I can modify video data on the fly at 1024x768 120
frames per second in 32 bit color. And that was on a 5 year old machine. Try
doing that in Java.

Michael
 
Michael D. Ober said:
What Rory said is that 99% of programmers don't need to use pointers. He
didn't say that they don't use them - just that their apps could be coded
without unsafe pointers. The fact that you seem to like them tells me
that you are either working in the few app domains that require pointers
(OS development)

Are you seriously suggesting that the only use for pointers is OS
development!?!
or that you use them instead of using other, demonstrably correct, methods
in your code.

There is nothing incorrect about using pointers. Assuming I wanted to gray
out of bitmap and dot net doesn't do it in the way I would like then I could
either use a third party library or do it myself using pointers. I suspect
you think using a third party library is the more "correct" solution but if
they're doing it correctly then they will be using pointers themselves. So
what have I achieved by handing over the pointer work to another programmer?
Perhaps you trust a third party programmer more than you trust yourself?

Michael
 
Hello Michael,
Perhaps you think pointers are more scary/dangerous than they really
are. To me they are no big deal, if I need to go through some data at
high speed then use a pointer. You can't get much more of a perfect
example than modifying an entire bitmap.

You're missing the point again. We have stated that there are relatively
few reasons to use a pointer in 2008 within the .Net Framework.
You have poorly engineered an excuse to use pointers (Greying a Bitmap in
a WebApp). As I pointed out... No competent Web programmer would use pointers
in this way as there are many other far more appropriate tools for the job.
What happens if you don't have the bitmap until runtime?

So you're narrowing the field yet again...

"Greying out a bitmap, when said bitmap doesn't exist until runtime."

....and I already covered this with my suggestion of CSS and JQuery, which
both operate at runtime, on the client machine.

One less reason to use pointers. Which means I (and others) can concentrate
efforts on more useful areas.
 
Herfried K. Wagner said:
Pointers are not that hard to understand.

They can be a bit of a mind warp, especially when you get into pointers to
pointers and start passing them around.
However, they are typically unsafe, cannot be checked at compile time, and
can thus increase the potential for bugs in the code and exploitation.

I think they just increase the amount of checking and testing you need to
do. Development speed is certainly reduced but if they are appropriate for
that particular task then the extra time is justified. Although quite often
they just shift the bugs from being run time errors to being access
violations. Either way if you make a mistake you still get some sort of
error.
I doubt that a beginner would struggle more with pointers than with OOP.

Beginners struggle big time with oop. Some of the "oop" code I've seen. No,
you do not pass a reference to a combo box into your class :-)
I've said you do not need to mention bitmap manipulation as I have already
mentioned it.

It is still a valid point.
Well, then just be happy that you have found what you are looking for.
Tastes are different and VB is not the same as C#.

I am :-)
Why not just use this (conceptional) code?

\\\
Dim OriginalImage As New Bitmap("C:\WINDOWS\Angler.bmp")
Dim Image As New Bitmap(OriginalImage)
OriginalImage.Dispose()
...
Image.Dispose()
///

I tried all options, there was a problem with all solutions I tried. I can't
remember all the details but I certainly didn't try to make an excuse to use
pointers. I don't think you have as much control in the above situation
because I converted everything to either 32bpp or 8bpp grayscale. You simply
cannot get faster than pointer code so in many cases it is the best
solution. I wrote an entire imaging app for dental surgeries in C# with no
third party libraries. Everything was done in C# such as Twain, DirectShow,
WIA, video for windows, IMAPI + some interaction with my own usb hardware.
... only as long as C# is sufficient. There are some things which cannot
be done in C# though. So the level of "breaking out to use C/C++" is just
different between VB.NET and C#, but it only differs slightly between the
two programming languages.

That's true.
I used pointers for years in C, which is one of my favorite programming
languages beside BASIC-style languages.

I'm suprised you don't use C# yourself. :-)

Michael
 
Hello Michael,
There is nothing incorrect about using pointers. Assuming I wanted to
gray out of bitmap and dot net doesn't do it in the way I would like
then I could either use a third party library or do it myself using
pointers.
So what have I achieved by handing over the
pointer work to another programmer?

The ability to concentrate my mind on things that actually matter to my client.


Things other than the details of exactly how grey the bitmap should become.

If I spend my time redoing already
Perhaps you trust a third party programmer more than you trust yourself?

I always trust a carefully chosen 3rd party to do specialist tasks, which
then frees me up to do the actual work I was contracted to do.

Again... The .Net Framework's *primary* use is LOB apps which have very few
reasons to use pointers.

Therefore while they will have their uses, pointers are just not that important
in the .Net Framework, hence in any language that uses it.
 
Rory Becker said:
You're missing the point again. We have stated that there are relatively
few reasons to use a pointer in 2008 within the .Net Framework.
You have poorly engineered an excuse to use pointers (Greying a Bitmap in
a WebApp). As I pointed out... No competent Web programmer would use
pointers in this way as there are many other far more appropriate tools
for the job.

Ok, so you need to gray the image out and do it in a custom style, say gray
it but to a certain color. You could probably use some of the transforms in
dot net but these are going to be slower and possibly more difficult to use.
So you're narrowing the field yet again...

I'm coming up with an example where you might need pointers. Modifying a
bitmap at runtime using some custom method is not exactly obscure.
"Greying out a bitmap, when said bitmap doesn't exist until runtime."

...and I already covered this with my suggestion of CSS and JQuery, which
both operate at runtime, on the client machine.

What if they don't do it in the way your boss has requested. One case I had
I needed to emboss an image but not to grayscale, to fit with the background
color of a page.
One less reason to use pointers. Which means I (and others) can
concentrate efforts on more useful areas.

You do realise that everything underneath is just using pointers. No matter
how you gray out that bitmap something is going to create a pointer and run
through that bitmap pixel by pixel. Perhaps you trust a third party to use
advanced techniques more than yourself but in my case I trust my ability
quite well enough. If you look at Paint.Net there is pointer use absolutely
everywhere.

Michael
 
Hello Rory,

I apparently did not complete this sentence... :)
If I spend my time redoing already

What I meant to say was....

If I spend my time redoing work already implemented perfectly well by a thirdy
party then I could well expect....

....to miss other project related issues whilst busy coding something I don't
need to.
....to code it worse than the experts I should have delegated to.
....the project to overrun
....the client to fire me or at the very least not employ my services again.
 
Hello Michael,
Perhaps you trust a third party to use advanced techniques more than
yourself but in my case I trust my ability quite well enough.

All Hail Michael C..

....King of "Not Invented here"
....Master of mistrust
....Lord of the pointer Hammer

He who is probably going to rewrite the .Net framwork itself over lunch :D
 
Back
Top