473,785 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Request for Code Review

I have created an open source Notepad program for Windows in C++ that allows
search and replace using regular expressions (and a few other extras). It
is located at http://www.codeproject.com/cpp/notepadre.asp

I'm trying to use best practice in my C++ programming and would appreciate
any advice anyone can give. As code is far more than just a one page
sample, just a review of one of the source files (or even just a function or
two) is equally welcome!

If you reply, could you also mail me at benjamin dot hanson at swx dot ch

Thanks!
--
~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #1
18 2150
* Ben Hanson:
I have created an open source Notepad program for Windows in C++ that allows
search and replace using regular expressions (and a few other extras). It
is located at http://www.codeproject.com/cpp/notepadre.asp

I'm trying to use best practice in my C++ programming and would appreciate
any advice anyone can give. As code is far more than just a one page
sample, just a review of one of the source files (or even just a function or
two) is equally welcome!
I'm currently a bit depressed because some folks who promised to
review something for me haven't even replied that they've not found
the time (or whatever). So I'll take a look at this, just to prove
to myself that it's no big hassle to review something. Then I can
go from depressed to perhaps a bit angry.

If you reply, could you also mail me at benjamin dot hanson at swx dot ch


Nope (see the FAQ).

Okay, first problem: in order to download the code one must provide a
username and password. I can't for the life of me remember what I chose
last time at that ****ing site. But there is a quick-register option
where I only have to supply an e-mail address. OK! But alas, "The
email you supplied has already been registered".

Now checking the mail to see if they've sent me my old username etc...

Nope. One idiot-mail from someone quoting a usenet posting of mine (in
sci.physics.res earc) and adding nothing more; one attempted virus
(automatically removed); one spam apparently from gl**********@ju mpy.it,
"Winning Notice", yeah right.

Okay, found option to have the site mail me my old username & password.

Now checking mail again...

Nope, nothing.

Now checking mail again...

Nope, nothing.

Now checking mail again...

Nope, nothing.

Now checking mail again...

Nope, nothing.

Now checking mail again...

Nope, nothing.

Well I ain't gonna create a new e-mail account just to download your
complete code, so I'll have to review just what you display on the page.

The first thing you state about the internals is that "Notepad RE is
CEditView based". Now what is "CEditView" ? Since this is Windows I
fire up my MSDN Library. Yeah, right, there is a CEditView class in
MFC. But, MFC? Why don't you use WTL?

* Recommendation: state first of all that this is an MFC app.

Some folks might say that has nothing to do with C++. But it has.
MFC is C in C++ disguise. WTL is at least template-based, although
it's Microsoft style with e.g. unsafe construction and all that.

The first bit of actual code displayed is

void CFindReplaceDlg ::OnCheckMatchC ase ()
{
m_pParentWnd->PostMessage (WM_NOTIFY_FIND _REPLACE, eMatchCase,
m_CheckMatchCas e.GetCheck ());
}

Now this is using a Windows API service in order to update (?) the
dialog owner window's state -- I think. But using that service
(message posting) seems to be unnecessary. And it introduces type
unsafety.

Better just call a method on the parent window (or a more restricted
interface) directly.

Next, we have

BOOL CFindReplaceDlg ::OnInitDialog( )
{
CDialog::OnInit Dialog ();

m_CheckWholeWor dOnly.SubclassD lgItem (IDC_CHECK_WHOL E_WORD, this);

if (m_bInitialRegE x)
{
m_CheckWholeWor dOnly.EnableWin dow (FALSE);
}
else
{
m_CheckWholeWor dOnly.SetCheck (m_bInitialWhol eWordOnly);
}

m_CheckMatchCas e.SubclassDlgIt em (IDC_CHECK_MATC H_CASE, this);
m_CheckMatchCas e.SetCheck (m_bInitialMatc hCase);
m_CheckRegEx.Su bclassDlgItem (IDC_CHECK_REGE X, this);
m_CheckRegEx.Se tCheck (m_bInitialRegE x);

if (m_IDD == IDD_FIND)
{
m_RadioUp.Subcl assDlgItem (IDC_RADIO_UP, this);
m_RadioDown.Sub classDlgItem (IDC_RADIO_DOWN , this);
m_RadioDown.Set Check (TRUE);
if (m_bInitialRegE x) m_RadioUp.Enabl eWindow (FALSE);
m_CheckCloseOnM atch.SubclassDl gItem (IDC_CHECK_CLOS E_ON_MATCH,
this);
}
else
{
m_EditReplaceTe xt.SubclassDlgI tem (IDC_EDIT_REPLA CE, this);
m_CheckReplaceA llLikeNotepad.S ubclassDlgItem
(IDC_CHECK_LIKE _NOTEPAD,
this);
}

m_EditFindText. SubclassDlgItem (IDC_EDIT_FIND, this);
m_EditFindText. SetWindowText (m_strInitialFi nd);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

The first thing I notice is inconsistent indentation size; previously it
was 4, now it's 2.

* Recommendation: use consistent indentation size.

The OnInitDialog mess is forced upon you by MFC; nothing much one can do
about that in an MFC-based application, but otherwise, use constructors
for construction.

* Recommendation: don't use MFC, it's not type-safe.

Next thing I notice is that there seems to be no failure checking. Not
even asserts. Perhaps that's because all those methods invoked are nice
enough to throw exceptions if they fail, but remembering what MFC was
like I rather doubt it.

* Recommendation: do check for failures.

Third thing I notice is that m_IDD == IDD_FIND is repeated later on in
other code.

This suggest that you should really have two different classes, perhaps
derived from a class that encapsulates the _common_ things.

* Recommendation: do use inheritance to factor out common things,
and do use different classes for objects with different
functionality.

New function, CNotepadreDoc:: OnNotifyFindRep lace. I'll not repeat the
code here, but it's one long if-then-elseif-elsif-elsif just checking
a variable's value against a set of possible (apparently) constant
values. Now that's perfectly OK technically, but it would be more clear
(especially that no other kind of condition is present) with a 'switch':

* Recommendation: do use 'switch' for 'switch' constructions.

New function, CNotepadreDoc:: OnOpenDocument.

Here you have some decidedly non-C++ exception handling based on _old_
MFC macros.

* Recommendation: do use modern C++ exception handling. Even
Microsoft says so in their documentation of MFC!

* Check out the ScopeGuard header (Google), use ScopeGuard for the
cleanup things you here use try-catch for, and in general (but not
in this specific case) use RAII (Google) rather than try-catch.

Now that's that, I think I've done enough to change my emotional state a
bit in the right direction, and in a short time!

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
Thanks for the prompt reply!

The ScopeGuard tip alone deserves that I return the favour. Can you post a
URL or zip?

Cheers

Ben
--
~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #3
* "Ben Hanson" <benjamin dot hanson at swx dot ch>:
Thanks for the prompt reply!

The ScopeGuard tip alone deserves that I return the favour. Can you post a
URL or zip?


Using Google the first real reference I found was the Norwegian
[no.it.programme ring.c++] FAQ (which I contributed to), at
<url: http://utvikling.com/cppfaq/04/04/02/>; see point D.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #4
Ben Hanson wrote:
I have created an open source Notepad program for Windows in C++


Sorry.
Your code does *not* comply with the ANSI/ISO C++ standard.
Try posting your request to an appropriate Microsoft Windows newsgroup.
Jul 22 '05 #5
Ben Hanson wrote:
I have created an open source Notepad program for Windows in C++ that
allows
search and replace using regular expressions (and a few other extras). It
is located at http://www.codeproject.com/cpp/notepadre.asp

I'm trying to use best practice in my C++ programming and would appreciate
any advice anyone can give. As code is far more than just a one page
sample, just a review of one of the source files (or even just a function
or two) is equally welcome!

If you reply, could you also mail me at benjamin dot hanson at swx dot ch

Thanks!


This may be a minority view, but I prefer to put a lot more comments in my
code.
--
Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Email Address: Please see my Home Page
Jul 22 '05 #6
E. Robert Tisdale wrote:
Ben Hanson wrote:
I have created an open source Notepad program for Windows in C++


Sorry.
Your code does *not* comply with the ANSI/ISO C++ standard.
Try posting your request to an appropriate Microsoft Windows newsgroup.


Isn't this a rather narrow point of view? It seems to suggest that this
newsgroup is for an elite cognoscenti, and that anyone else should go away.

Perhaps that is not what you intended, but that is the impression that comes
across.
--
Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Email Address: Please see my Home Page
Jul 22 '05 #7
"Chris Gordon-Smith" <ad*****@homepa ge.net> wrote in message
news:2k******** ****@uni-berlin.de...
E. Robert Tisdale wrote:
Ben Hanson wrote:
I have created an open source Notepad program for Windows in C++
Sorry.
Your code does *not* comply with the ANSI/ISO C++ standard.
Try posting your request to an appropriate Microsoft Windows newsgroup.


Isn't this a rather narrow point of view?


By necessity, the topic of this group is as 'narrow' as the
standard C language. If it were otherwise, there are so
many platform-specific and third-party libraries and interfaces,
etc. that it would be nigh impossible for those interested only
in the language (the topic here, after all) to locate posts
about it.
It seems to suggest that this
newsgroup is for an elite cognoscenti,
It's for those who discuss ISO standard C, regardless of their
knowledge and skill levels with it. If you consdier that group
to be 'elite', so be it.
and that anyone else should go away.
Anyone is welcome to read and post topical articles here.
Perhaps that is not what you intended, but that is the impression that comes across.


Robert appears to frequently annoy many folks here, but imo
this time he's right. Perhaps one might find his post lacks
tact.

But think about it. In order to intelligently discuss Ben's
code, one need to understand and discuss the Windows API,
which has *nothing* to do with ISO C. Ben would get much
better and high quality responses from Windows experts by
posting to a Windows group, e.g. comp.os.ms-windows.program mer.32
(I read that group fairly frequently, and there are a few imo quite
impressive 'gurus' that answer questions there.

If I want high quality information, advice, or assistance with
ISO C, I post here. Here is where the C experts discuss C
(not Windows or anything else).
-Mike
Jul 22 '05 #8
"Mike Wahler" <mk******@mkwah ler.net> wrote in message news:dpmFc.2982 >

.... some stuff.

Change all occurrences of C to C++.
Sorry about that.

-Mike
Jul 22 '05 #9
Chris Gordon-Smith wrote:
E. Robert Tisdale wrote:
Ben Hanson wrote:
I have created an open source Notepad program for Windows in C++
Sorry.
Your code does *not* comply with the ANSI/ISO C++ standard.
Try posting your request to an appropriate Microsoft Windows newsgroup.


Isn't this a rather narrow point of view?
It seems to suggest that this newsgroup is for an elite cognoscenti,
and that anyone else should go away.


The opposite is true.
Ben Hansen's implementation is restricted to "an elite cognoscenti"
consisting of Microsoft Windows C++ programmers.
No one else can actually compile his code much less comment on it.

Ben should submit his request for a code review to a forum
consisting of "an elite cognoscenti"
that specializes in Microsoft Windows C++.
Perhaps that is not what you intended,
but that is the impression that comes across.


Subscribers to the comp.lang.c++ newsgroup have wider interests
than Microsoft Windows C++.
Perhaps you don't mean to be inconsiderate or disrespectful of them
but that's the impression that comes across.
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1712
by: Adam Monsen | last post by:
I kindly request a code review. If this is not an appropriate place for my request, where might be? Specific questions are in the QUESTIONS section of the code. ========================================================================== #include <stdio.h> #include <stdlib.h> #include <string.h>
6
3147
by: Daniel Rimmelzwaan | last post by:
I want to send a biztalk document to an aspx page, and I need to see some sample code, because I just can't make it work. I have a port with transport type HTTP, pointing to my aspx page, something like http://myserver/mypage.aspx. From there it gets blurry, because I just can't figure out how to do the rest. Does anybody have a sample page for me that I can take a look at? Just a simple one that takes whatever biztalk sends and saves it...
2
7866
by: William F. Robertson, Jr. | last post by:
Some of my users are receiving an error: Server Error in '/' Application. ---------------------------------------------------------------------------- ---- Request timed out. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
0
3834
by: Jack Wright | last post by:
Dear All, I have a web Application "http://localhost/Web/WebForm1.aspx" that calls a WebService from "http://localhost/webserviceapp/service1.asmx"...I have set the executionTimeout to 10 secs in Web.Config where my WebService is installed. <httpRuntime executionTimeout="10" appRequestQueueLimit="2" /> When I call a method "TestPlan" which takes more than 10 secs my web Page gets the following error:
2
1717
by: Terry Mulvany | last post by:
namespace CIBWeb { public class BasePage : System.Web.UI.Page { public BasePage() { } protected override void OnInit(EventArgs e) {
7
4146
by: Shapiro | last post by:
I have a scenario where I log a resquest to a database table and update the request with a corresponding response including the response time. I am using an HttpModule to do this. My challenge is how to corelate the response to a corresponding request. I am looking for a sure proof threadsafe way to corelate a response to a coresponding request message. Two things that concerns me:-
3
17820
by: nms | last post by:
I've an ASP.net web site, Since last some days, Users are experiencing problem when they try to generate reports (for a large date range) it says, Request timed out. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information
2
9818
by: patrice.pare | last post by:
Hello, Here is a summary of my Dev Environment: I use Visual Studio 2005 Team Suite SP1 with Crystal Report XI SP1 on a Windows XP SP2 development workstation. I also use SQL Server 2000 SP4. And here a summary of what is the problem: I have a web application that has a web form into which I read data from a SQL database and load them in a ReportDocument of Crystal
3
2294
by: vijaykumardahiya | last post by:
Dear Sir, I have two queries. First question is: I have a Html page. On which Have two buttons Submit and Issue. I want when I click on Sumit button request should be go to submit.jsp. and When I click on Issue button then request should be go to Issue.jsp.But When I click on submit button request do to Issue.jsp. Second Question is How I reterive the input parameter of html page to submit.jsp. Please review.. My files are: login.html:
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.